I need to perform a GET request to a url, with optional URL parameters.
The basic URL looks something like http://host/user/explore
, with the option of querying http://host/user/explore?who=VALUE&category=VALUE&service=VALUE
for more accurate results.
For the first case the response comes with keys at the root, such as:
{
"professionals": [
{
"_id": "59e8576cb524cf44a435844b"
}
],
"salons": [
{
"_id": "59e857bbb524cf44a4358454"
}
]
}
And I am able of successfully mapping the response by setting up my response descriptor such as:
RKResponseDescriptor *response = [RKResponseDescriptor
responseDescriptorWithMapping:[Explore map1]
method:RKRequestMethodGET
pathPattern:@"user/explore"
keyPath:nil
statusCodes:RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful)];
return response;
(note that the [Explore map1]
accounts for mapping an NSArray of "Professional" and another one made up of "Salon" NSObjects)
However, when I query http://host/user/explore?who=VALUE&category=VALUE&service=VALUE
, my response JSON becomes:
{
"_id": "59f6f9fc36e51720da2e85f4"
},
{
"_id": "92x2f9fc36e51720da2e66d5"
}
Where the actual returned objects are all of the same type (and no longer have a key at the root).
So now obviously, my RKResponseDescriptor
and RKObjectMapping
are failing to properly handle this case.
I've looked into using RKDynamicMapping
or RKRoute
and wasn't able of really getting a handle on how they work or if they're even applicable to my case...