Reputation: 2585
I'm trying to POST
the following JSON using the [RKObjectManager sharedManager] postObject
method:
{
"SerialNumber":"123XYZ"
}
But my web service receives:
{
"docs\/:docId\/serials":{"SerialNumber":"123XYZ"}
}
Where "docs\/:docId\/serials"
is the path
parameter I pass into the [RKObjectManager sharedManager] postObject
method, specifying the path needed for my web service method.
Does anyone know why this extra path data is included in the body contents being posted?
The mapping from my NSObject based class seems to be working fine, the correct serial number is passed through into the JSON. I've set the RKObjectManager to use a MIME type of JSON on requests, using the following code, it wouldn't be anything to do this would it?
objectManager.requestSerializationMIMEType = RKMIMETypeJSON;
Any clues would be much appreciated, and I'll happily post up more code if needed too.
Thanks in advance.
Upvotes: 0
Views: 56
Reputation: 2585
Ah, naturally 5 minutes after posting this, I worked out the relatively obvious cause of this problem.
When setting up my RKRequestDescriptor
for this operation, I was passing in the path to my web service method in the rootKeyPath
parameter, thinking that RestKit needed this to act as a key, to find this descriptor when I called the postObject
method later.
However, when I removed the web service path from the rootKeyPath
parameter, it disappeared from the POST
body too.
RKRequestDescriptor *addSerialRequestDescriptor = [RKRequestDescriptor requestDescriptorWithMapping:addSerialRequestMapping objectClass:[Serial class] rootKeyPath:nil method:RKRequestMethodPOST];
I realise now I was getting the rootKeyPath parameter in the RKRequestDescriptor requestDescriptorWithMapping:
method, mixed up with the pathPattern parameter in the RKResponseDescriptor responseDescriptorWithMapping:
method, which (as I understand RestKit) does need to have the path to the web service method passed into it.
Hopefully this might help someone else one day, and apologies for wasting everyone else's time!
Upvotes: 1