Q&A about Collection+JSON

Note: The content in this post is not mine. It is just a collection of questions and answers from the Collection+JSON discussion group. I’ve been working with this hypermedia-type lately, and ran into many doubts. Reading through the disscussion group was time consuming, so I’ve gathered this as a future reference for myself and others. However, this should not stop you from doing your own research and spend some time reading the docs and the discussions.

General

How does a Collection+JSON response look like?

Isn’t this C+J thing very limited? It should do this, and that, and this other thing too…

I also had this feeling. Read this thread, please, to distinguish beetwen C+J concerns and applciation concerns.

PS: Read it.

Items / Data

What about nested data (i.e. model associations)?

Amudsen (edited): Cj was initially designed to not support embedded objects or deep graphs. However, there is at least one extension registered called inline Collections. If nesting within a representation is essential, Cj will not be a good fit for you w/o a specific extension.

Source here.

Templates

What if different templates for POST and PATCH are needed?

Amudsen (edited): The assumption in Cj is to use the template for both updates (PUT) and creates (POST). This is based on the idea that the data set written in both cases is the same. In cases where the update action does not match the create action details, the approach I suggest is to use a link in the item and points to a representation that has the needed template. There is a problem here in the that second representation looks like a “create” description. I hack around this by telling the client app that when following an “edit” link, you SHOULD use the PUT method. Again, this is convention, not spec.

A way around this assumption that I am making is to extend the template to add a method argument. But that’s an extension I’ve not registered and not heard a lot of request for yet.

I should also point out that at least one “templates collection” extension has been registered.

Source here.

What if a field needs options, as for the select, checkboxes or radio?

The C+J spec does not consider this, but a workaround (that you’ll need to build support for) is:

Source here.

October 9, 2014