To handle a GET/POST request/response with RestKit 0.20 you can follow below sequence :-
At very first configure RKObjectManager with the base server URL :-
RKObjectManager *manager = [RKObjectManager managerWithBaseURL:baseUrl];
[manager.HTTPClient setDefaultHeader:@"Accept" value:RKMIMETypeJSON];
manager.requestSerializationMIMEType = @"application/json";
Since RestKit always deal with objects for request and response, you must have to create an object having all the parameters that you expect in response.
@interface AuthenticationRequest : NSObject
@property (nonatomic, copy) NSNumber *userName;
@property (nonatomic, copy) NSString *password;
@end
@interface AuthenticationResponse : NSObject
@property (nonatomic, copy) NSNumber *token;
@property (nonatomic, copy) NSString *expiryDate;
@property (nonatomic, copy) NSString *userId;
@end
Then configure request and response mapping for the instance variables in your local objects with the keys in server JSON response.
NOTE: configure request mapping only in case of POST or PUT request.
RKObjectMapping *requestMapping = [RKObjectMapping mappingForClass:[AuthenticationRequest class]];
[requestMapping addAttributeMappingsFromDictionary:@{
@"userName": @"userName",
@"password" : @"password",
}];
RKObjectMapping *responseMapping = [RKObjectMapping mappingForClass:[AuthenticationResponse class]];
[responseMapping addAttributeMappingsFromDictionary:@{
@"TOKEN": @"token",
@"expiryDate" : @"expiryDate",
@"USERID": @"userId"
}];
Then create a response descriptor that will perform mapping of server JSON object with your local object based on the pathPattern value that you passed it.
RKRequestDescriptor *requestDescriptor = [RKRequestDescriptor requestDescriptorWithMapping:requestMapping objectClass:[AuthenticationResponse class] rootKeyPath:nil]
[manager addRequestDescriptor:requestDescriptor];
RKResponseDescriptor *responseDescriptor = [RKResponseDescriptor responseDescriptorWithMapping:mapping pathPattern:<rest of the path excluding the baseURL> keyPath:nil statusCodes:nil];
[manager addResponseDescriptor:responseDescriptor];
Now perform GET request on server in following way :-
[manager getObjectsAtPath:(NSString *)<rest of the path excluding the baseURL> parameters:(NSDictionary *)parameters
success:(void (^)(RKObjectRequestOperation *operation, RKMappingResult *mappingResult))success
failure:(void (^)(RKObjectRequestOperation *operation, NSError *error))failure];
or perform a POST request on server in following way :-
[manager postObject:AuthenticationRequest
path:<rest of the path excluding the baseURL>
success:(void (^)(RKObjectRequestOperation *operation, RKMappingResult *mappingResult))success
failure:(void (^)(RKObjectRequestOperation *operation, NSError *error))failure];
the success and failure blocks will hold your handling for the response.
For more help you can refer following link from RestKit :-
https://github.com/RestKit/RKGist/blob/master/TUTORIAL.md