TestsTested | ✓ |
LangLanguage | Obj-CObjective C |
License | Apache 2 |
ReleasedLast Release | Nov 2016 |
Maintained by David Kettler, Mayuko Inoue, Seansy Holbert.
Easily integrate your Realm models with a JSON:API compliant server
JSONtoModelMap
(and we strongly recommend defaultAttributes
and defaultRelationships
as well)Register the model early in the application's lifecycle via
[[JSONAPIResourceRegistry sharedInstance] bindJSONType:@"your-model-type" toClass:[Model class]]
Parse server responses with
[JSONAPIParserUtilities putJSON:serverResponseDict inRealm:[RLMRealm defaultRealm]]
[model toJSON]
(made accessible via #import <Realm_JSONAPI/RLMObject+JSONAPI.h>
) and send it to the serverTry out a full example project with
pod try Realm-JSONAPI
Typical usage in a single RLMObject subclass file looks something like this:
#import <Realm_JSONAPI/RLMObject+JSONAPI.h>
@interface User : RLMModel
@property NSString *uid;
@property NSString *name;
@property NSString *email;
@property NSString *avatarURL;
@end
@implementation User
+ (NSDictionary *)JSONtoModelMap {
return @{
@"id" : @"uid",
@"full_name" : @"fullName",
@"email" : @"email",
@"image_url": @"avatarURL",
};
}
+ (NSArray *)defaultRelationships {
return @[];
}
+ (NSArray *)defaultAttributes {
return @[
@"full_name",
@"email",
@"image_url",
];
}
+ (NSString *)primaryKey {
return @"uid";
}
+ (void)fetchUser:(NSString *)uid {
NSString *baseURL = [NSString stringWithFormat:@"users/%@", uid];
[APICall queueWithURL:[[self class] defaultURLDecoration:baseURL]
params:nil
method:HttpMethodGET
andCallback:callback];
}
- (void)patchWithCallback:(APICompletionBlock)callback {
NSString *baseURL = [NSString stringWithFormat:@"users/%@", self.uid];
[APICall queueWithURL:[[self class] defaultURLDecoration:baseURL]
params:[self toJSON]
method:HttpMethodPATCH
andCallback:callback];
}
You can read the full docs at http://cocoadocs.org/docsets/Realm-JSONAPI
Realm and a JSON:API-compliant server
Realm-JSONAPI is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod "Realm-JSONAPI"
David Kettler, [email protected]
Realm-JSONAPI is available under the Apache 2.0 license. See the LICENSE file for more info.
git clone [email protected]:Patreon/Realm-JSONAPI.git
cd Realm-JSONAPI
git checkout -b my-meaningful-improvements
Example/Realm-JSONAPI.xcworkspace
and running tests with Cmd+U
(you may need to cd Example && pod install
first)git push origin my-meaningful-improvements
hub pull-request
, if you have hub
)