Skip to content

Instantly share code, notes, and snippets.

Created Aug 17, 2011
What would you like to do?
What is the best format for RestKit?
RestKit allows a great deal of customization and can probably be made to handle most formats.
Since I have full control over the server (now), I want to put the onus on the server as much
as possible and reduce unnecessary bandwidth. However, I want to keep the RestKit side code
as easy, and concise as possible.
So suppose I have a set of widget classes with ids and names with standard CRUD operations.
I have an index action which could potentially return a large number of widgets and so need
to be paginated. Here is one way I thought of.
Create Action
iOS Sends: { widget: { name: "foo" } }
Server Responds: { widget: { id: 3, name: "foo", user_id: 30 } }
Read Action
iOS Sends: { page: 1} (or nothing at all)
Server Responds: { pagination: { page: 1, per_page: 100, total: 1000 }, widgets:
[ widget: { id: 1, name: foo, user_id: 30}, widget: { id: 2, name: foo, user_id: 30}, ... } ] }
Update Action
iOS Sends: { id: 200, widget: { name: "new name foo" } }
Server Responds: { widget: { id: 200, name: "foo", user_id: 30 } }
Destroy Action
iOS Sends { id: 3 }
Server Responds head :ok
Does this look like a good way to structure things, or are there better formats that make the
RestKit code easier?
Copy link

rayfix commented Aug 18, 2011

On Aug 16, 2011, at 6:48 PM, Blake Watters wrote:

This looks pretty reasonable to me. I would probably centralize the pagination logic into the target class of the pagination keyPath and use that object to mint additional object loaders to paginate in additional results. There may be an opportunity to build a reusable piece of pagination code around this case...


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment