I have two routes:
POST /food.json
Request body:{"food": {"name":"Banana", color:"yellow"}}
Request Descriptor:
RKRequestDescriptor *createRequestDescriptor = [RKRequestDescriptor requestDescriptorWithMapping:createMapping
objectClass:[Food class]
rootKeyPath:@"food"
method:RKRequestMethodPOST];
--
POST /food/batch.json
Request body: {"foods": [{"name":"Banana", color:"yellow"}, {"name":"Apple", "color":"red" }]}
Request Descriptor:
RKRequestDescriptor *batchRequestDescriptor = [RKRequestDescriptor requestDescriptorWithMapping:createMapping
objectClass:[Food class]
rootKeyPath:@"foods"
method:RKRequestMethodPOST];
--
The problem I am running into is the that the create and batch request both use POST request methods, so if I try to add them both as request descriptors, I get:
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Cannot add request descriptor: An existing descriptor is already registered for the class 'Food' and HTTP method'(POST)'.'
Is there a conditional for request descriptors where I can say:
Use the batchRequestDescriptor
for path /food/batch
and use the createRequestDescriptor for the /food
path?
In this case you would use named routes (RKRoute
Instances), and when you want to make a POST you would use requestWithPathForRouteNamed:object:parameters:
and then create your operation from the route.
It's more common to see your situation for GET and that's why getObjectsAtPathForRouteNamed:object:parameters:success:failure:
exists, but you will need to do a little more work (and/or create your own convenience method).