cocoa touch - API Key and RESTKit -
i'm using restkit service created me. model in json user is:
{ "api_key" : "123456" "user" : { "username" : "user1", "email" : "me@email.com", "name" : "name1", "surname" : "surname1" } }
i need introduce api_key
if want user /users/1.json
. read in documentation set app-wide api key http header.
the example is:
[client setvalue:@"123456" forhttpheaderfield:@"x-restkit-api-key"];
is right way this? how can discover @"x-restkit-api-key"
of service? (not api_key value, search string replace @"x-restkit-api-key"
service)
hmm, sample request, suggest use rkclient object. give example:
#import <restkit/restkit.h> #import "jsonkit.h" rkclient* client = [rkclient clientwithbaseurl:@"http://yourdomainwhereisapi.com"];
and anywhere in app (because rkclient singleton object) can call:
// here need define delegate in header (because delegate self) // declare delegate in .h file <rkrequestdelegate> [[rkclient sharedclient] get:@"/some/api/call.json" delegate:self];
you must define delegate method:
- (void)request:(rkrequest*)request didloadresponse:(rkresponse*)response { // handle response object // sample how make nsdictionary json response nsdictionary *deserializeddata = [[response bodyasstring] objectfromjsonstring]; // can nsdictionary: nslog("%@", [deserializeddata objectforkey:@"api_key"]; }
p.s. anyway, can take @ restkit wiki see basic examples: restkit wiki tutorial
Comments
Post a Comment