Internet-Draft: JSON Hypertext Application Language (lean format for linking)
raw.github.com
raw.github.com
From their examples, this is the equivalent representation:
Link: <http://www.tld/orders/523>;rel=self, <http://www.tld/warehouse/56>;rel=warehouse, <http://www.tld/invoices/873>;rel=invoice
It also allows for multiple Link headers to be sent instead of the comma-separated version.Github already use hal+json's _links convention in their latest Pull request API: http://developer.github.com/v3/pulls/
The practical problem is that you have to parse the link header, and it's not simple enough for common use. I think, if we want to use headers, we need to build some JS utilities for the different specs that abstract away any parsing.
There are problems with using Link headers, I think you will find less friction in practice by treating links as 'proper data' and putting them in the content body using a media type like this.
You may be right-- HTML employs meta-data in the header, and there are good reasons for it. I like to think that I can put my meta links in the headers and content links in the json, but I may be overworking for a minor gain in simplicity.
We've been using it recently and we like it a lot.
Hopefully it holds up even though this choice might not be to everyone's taste?
https://groups.google.com/forum/?fromgroups#!topic/restful-j... (Google Groups breakage; link is meant to go to first post in discussion)
Instead of requiring that objects have a special _links property, you can put links anywhere in a JSON structure, just like in a HTML document.
Everything of the form
{ "$href": <url> [,"rel": <token>] [,"type": <media-type>] }
anywhere in a JSON object is treated as a link.- Resources - Resource state - Links
hal+json results in more uniform representations, which makes it easier to write generic client + server client libraries for
I tend to agree with the idea that self should be top-level, but the other thing I'd like to have in the specification is versioning for both the specification itself and the API. How about something like:
{ ... "_version": { "hal": <some HAL version string>, "api": <some API version string> }, ... }
Thanks for the thought you've obviously put into this ... we'll all benefit eventually!
already working on a browser: https://github.com/mikekelly/hal-browser
very rough demo here: http://hal-shop.heroku.com/hal_browser.html
There are strong arguments against that idea I'm sure, but consider the boon to adoption you can get by having the only required thing be a top-level element not a nested attribute