Sorry for the dramatic subject. I tweeted this today:
> an issue I have with collection+json is that it's not really json-like. What HAL does well is that it augments simple objects
I had a bit of a discussion with Mike Amundsen after that, who asked me if I wanted to elaborate on this list.
I want to preface this with saying that I think Collection+JSON is very interesting. I've been watching it for a while, and I would enjoy building systems on top of it. I hope to find some use-cases in the future where it's appropriate.
Today my use-case is calendaring. For calendaring CalDAV is the most common standard. But CalDAV is based on WebDAV, and comes with a lot of cruft. While powerful, DAV doesn't really match what developers in 2015 expect from an API. I am a member of
CalConnect, and from within that organization we are starting to look if we can build a new API for our abstract data-model.
A big goal if this new API would be to lower the barrier to entry to calendaring. For that reason we are looking at JSON.
In an attempt to do things 'right' this time, I managed to convince people to first just think about the 'mediatype', and ignore requests, urls, etc. We already have text/calendar to express events, and its companion
jCal which is a direct mapping of iCalendar to JSON. It's likely that we recommend that the endpoints that are going to serve up individual events and todos will at least support iCalendar, and perhaps jCal.
What we have not decided yet, is how we are going to express a 'list of events'. 'A list of events' in CalDAV is a 'calendar collection resource' or the result of a search query. To get a list of events, the PROPFIND and REPORT http methods are used, and a WebDAV multistatus XML response is returned along with a 207 status code.
We need to replace this, but it would also be nice to not have to reinvent the wheel. So I've looked at HAL, Collection+JSON, JSON-API, SIREN, XRD/JRD and JSON-LD.
The main features I am looking for are:
- A standard way to express link relationships.
- A standard way to express a collection of resources (with some information about these resources)
The reason I rejected Collection+JSON is for two reasons:
- It's not aesthetically pleasing.
- Data values can not be objects, they must be expressed as linked collection resources.
I don't think I need to elaborate on #2, but I will explain why #1 is important:
The benefit that HAL (and others) have, is that they augment simple json objects. This means that for all the people that don't care about HATEAOS, they can still use the a json endpoint in this way: (PHP example)
Now you might consider this a weak technical argument, and it is. Mike says:
"yes. that was by design. Cj is not code, it's *msg*. just as HTML relies on DOM for programming, Cj has a DOM, too."I agree with Mike. With a good Cj client my code sample could still be a 2-liner. How the information is transmitted over the wire
shouldn't matter. It
should be an implementation detail, and the message on the wire
should be the most effective expression of the data-model it represents.
But I feel that the reality is that people do care how it looks. The reason why formats such as HAL exist, is because people *want* to work with plain json objects. This is an important factor for me. I want to build an API that people *want* to use, and as a result we might go with a mediatype that's closer to "idiomatic JSON apis", trading in the technical benefits that Cj would otherwise provide.
The other reason is that I do not believe I can get people on board. If even I personally felt that Cj is the better choice, I am not going to be able to convince the rest of members of the working group. Suggesting using any standard media-type was already a battle and so was convincing people to use URIs for identifiers. Cj will be perceived as not being able to meet one of our main goals: to lower the barrier of entry to calendaring APIs.
So... this is my line of thinking. I hope this is useful and not discouraging. I want to live in a world where formats such as Collection+JSON are the both the standard and the popular choice, then this trade-off will not have to be made.
Evert