3 ms·
I don't get why so much negativity towards this. I have recently used this in a project where I was working on an iOS client to talk with a REST API based on JS
by rahultir 12y ago
I don't get why so much negativity towards this. I have recently used this in a project where I was working on an iOS client to talk with a REST API based on JSON API.
I'm not sure about the server-side implementation, but using it client-side was a breeze. I managed to completely automate my web-service calls to automatically parse/generate the required JSON and update the resources client-side.
Then, all I had to do to interact with new resources was register resources client-side with it's mappings.
@interface ModelResource : NSObject
+ (NSString)resourceName;
+ (NSString)resourcePluralName;
- (void)createMappings;
- (void)addAttributeMapping:(NSString)attributeName toProperty:(NSString)propertyName;
- (void)addLinkMapping:(NSString)linkName toProperty:(NSString)propertyName withResourceName:(NSString)resourceName;
- (void)fromJSON:(NSDictionary)jsonData;
- (NSDictionary)toJSON;
@end
@interface UserModel : ModelResource
@property (nonatomic, copy) NSString fullName;
@property (nonatomic, copy) NSString firstName;
@property (nonatomic, weak) EmailModel emailAddress;
@end
@implementation UserModel
+ (NSString )resourceName
{
return @"user";
}
+ (NSString )resourcePluralName
{
return @"users";
}
- (void)createMappings
{
[super createMappings];
[self addAttributeMapping:@"fullName" toProperty:STR_PROP(fullName)];
[self addAttributeMapping:@"firstName" toProperty:STR_PROP(firstName)];
[self addLinkMapping:@"emailAddress" toProperty:STR_PROP(emailAddress) withResourceName:[EmailModel resourceName]];
}
@end