I’m using RestKit to access a Tastypie API. I have control of both ends.
I have configured RestKit mapping to successfully load a “naked” JSON resource at `/api/v1/organizations/1/ like this:
{
"id": "1",
"name": "ACME Space"
}
But how do I configure RestKit to load a resource at /api/v1/organizations/ that looks like this:
{
"meta":
{
"limit": 20,
"next": null,
"offset": 0,
"previous": null,
"total_count": 2
},
"objects":
[
{
"id": "1",
"name": "ACME Space"
},
{
"id": "2",
"name": "XYZ Tech"
}
]
}
I assume that RestKit doesn’t like the meta key or the objects key being used for an Organization object.
I’m trying to do this with a RKFetchedResultsTableController. Is there a delegate callback that I can override or a class I can subclass to strip away the extra JSON that RestKit doesn’t like? Is it perhaps easier to change the way Tastypie emits the JSON response?
This question is similar to this unanswered SO question.
I would recommend that you take a look at the feature/reboot-networking-layer branch that is currently in the late stages of development. One of the many features in there is a harmonization of key-path and URL based mapping configurations using a new class called
RKResponseDescriptor. Basically this lets you say, when I load an object at this path pattern (in this case, /api/v1/organizations) map the ‘objects’ key path using the given mapping. This works around previous problems with key path ambiguity for generic key paths like ‘objects’.There is extensive documentation in the headers (published at http://restkit.org/api/0.20.0-dev/index.html) and a new README.md published to https://github.com/RestKit/RestKit/tree/feature/reboot-networking-layer.