I use RestKit to interact with a REST api. For some of the actions, like HTTP PUT/POST/DELETE, I only care about the response status code (200, or 500 etc), and don't care about the response data, even though the API does send back data.
For performance consideration, is there a way to configure RestKit to avoid mapping the response? It seems that if I don't set up a response descriptor I am getting the error "no response descriptors match the response loaded"
My solution was just to use a mapping for an NSObject
RKObjectMapping * emptyMapping = [RKObjectMapping mappingForClass:[NSObject class]];
RKResponseDescriptor * responseDescriptor = [RKResponseDescriptor responseDescriptorWithMapping:emptyMapping
method:RKRequestMethodPOST
pathPattern:API_SURVEY_UPLOAD keyPath:nil
statusCodes:[NSIndexSet indexSetWithIndex:200]];
[objectManager addResponseDescriptor:responseDescriptor];
If you don't need to map the response data to objects nor map objects to request params, you might be interested in using AFHTTPClient, which is what RestKit 0.20 uses anyway. You can access the AFHTTPClient object that RestKit itself uses, so you don't have to set up the base URL or authentication headers, etc. yourself all over again.
Here's a simple GET example:
[[[RKObjectManager sharedManager] HTTPClient] getPath:@"http://example.com"
parameters:nil
success:^(AFHTTPRequestOperation *operation, id responseObject) {
// handle success
}
failure:^(AFHTTPRequestOperation *operation, NSError *error) {
// response code is in operation.response.statusCode
}];
No, as the error suggests you need some response descriptor defined. It doesn't need to be complex (it can map a single data item like a status flag into an NSDictionary).
Don't worry about performance until you have reason to (profiling shows a problem).
That said, the most efficient way for RestKit to operate (at runtime) is to not have multiple response descriptors to search through, so be as specific as you can with path patterns and keypaths.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With