Set post body in RestKit manually

In some cases while using RestKit, you might want to set the post body (request params) manually with a JSON string instead of assigning an NSDictionary to it. Here’s the simplest way to do it.

1
2
3
4
5
6
RKClient *client = [RKClient sharedClient];
NSString *postBody = @"{\"key\":\"value\"}";
NSData *postBodyData = [postBody dataUsingEncoding:NSUTF8StringEncoding];
RKRequest *request = [client post:@"/endpooint"
                           params:[RKRequestSerialization serializationWithData:postBodyData MIMEType:RKMIMETypeJSON]
                         delegate:self];