1

I am making rest call as this

GET /entities?parent=123
[
    {id:1, name:"name 1"},
    {id:2, name:"name 2"}
]

My entity defination have following fields

id
name
parent

The problem is that parent field is not coming in the response, It is in the request. How can I save parent field from request to coredata?

I have tried to search these things with no luck.

  • I have tried looking for some transformers which could transform response before being processed by restkit but could not find anything.
  • I have seen Metadata Mapping in RKObjectRequestOperation but could not figure out if/how this can be used.

thanks

EDIT

Answer provided below works only if that is used with object manager. So the following works

RKDynamicMapping *learningObjectMapping = [MTAbstractLearningObject map];//this contains metadata mapping for @metadata.routing.parameters.entityId
RKResponseDescriptor* learningObjRd = [RKResponseDescriptor responseDescriptorWithMapping:learningObjectMapping 
    method:RKRequestMethodGET pathPattern:@"entity/:entityId" keyPath:@"objects" 
    statusCodes:RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful)];
[self.objectManager addResponseDescriptor:learningObjRd];
[self.objectManager.router.routeSet addRoute:[RKRoute routeWithName:@"learningObjects" pathPattern:@"entity/:id" method:RKRequestMethodGET]];

If object manager is constructed as shown above, and requests are made as shown below.

[self.objectManager getObjectsAtPathForRouteNamed:@"learningObjects" object:entity parameters:nil success:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult) {
    NSLog(@"API: Success got learning objects");
}failure:^(RKObjectRequestOperation *operation, NSError *error) {
    NSLog(@"API: Failed to get learning objects");
}];

Then it will work.

hridayesh
  • 1,123
  • 1
  • 14
  • 36

1 Answers1

1

You can use metadata, it includes a dictionary of query parameters that you can access. Your mapping will contain

@"@metadata.query.parameters.parent": @"parent"
Wain
  • 118,658
  • 15
  • 128
  • 151
  • you mean i can use this in RKEntityMapping? one more thing. In my case parameter is not in query string but part of url like /entites/parent/123 – hridayesh Jun 12 '15 at 15:15
  • I was looking for concept about this. Got good pointers from this answer to explore further. Trying to find documentation about metadata mapping. got http://cocoadocs.org/docsets/RestKit/0.24.1/Classes/RKMappingOperation.html Thanks for the answer. – hridayesh Jun 12 '15 at 16:59
  • if you're using path components instead then you should be looking into `RKRoute` – Wain Jun 12 '15 at 18:04
  • Let me dig more into that. then I will update answer and accept it. Thanks – hridayesh Jun 13 '15 at 04:47