News for hackers. Stuff that matters.
Re:The Restful CookBook by petrbela on Sunday May 24, 2015 @12:28PM (#9596683)
While some of the tips are useful, I'd much rather see them written with JSON rather than XML. JSON has long been an industry standard. XML is bloated, almost no one uses it anymore.

http://restcookbook.com/Mediatypes/json/ says "There is no predefined way to deal with link discovery in JSON". I'm surprised it doesn't even mention JSON Schema (http://json-schema.org/) or JSON API (http://jsonapi.org/), which are not official standards but allow you to write machine understandable and discoverable API.

If the author wants to promote standards, I think it would be better to look at what the world is using and then put together a guide that explains how to use JSON-LD and other W3C proposals.

Re:The Restful CookBook by jaytaph on Sunday May 24, 2015 @01:54PM (#9596960)
I think some of the articles actually talk about json-hal and ld. Not sure about schema.

The examples are in XML because json is, (and I believe at this point), still not stricly an (accepted) hypermedia capable format, thus not adhering the HATEOAS constraint, and thus cannot be restful. But to be honest, I'd prefer JSON over XML anytime.

Please, if you have any idea's on how to improve the site, the whole idea was to set up a small set of articles which others could help out expanding. It turned out that not many people actually posted their idea's (or even complete posts), so what you see on the site is pretty much the same thing as 2-3 years ago. I'd love some more PR's on expanding with up-to-date technologies and techniques (even those who aren't truly restful)

Re:The Restful CookBook by deathanatos on Sunday May 24, 2015 @02:30PM (#9597072)
> The examples are in XML because json is, (and I believe at this point), still not stricly an (accepted) hypermedia capable format, thus not adhering the HATEOAS constraint, and thus cannot be restful. But to be honest, I'd prefer JSON over XML anytime.

What exactly is the criteria of being a "hypermedia capable format"?

The linked website gives an example of how the response on a bank-account like API might include links to other actions; XML and JSON seem equally capable here, as they can both encode links.

He mentions on another page,

> Unfortunately, JSON is not a hypermedia format. There is no predefined way to deal with link discovery in JSON.

Is there a predefined way to deal with it in XML? In the earlier example, I had assumed he did exactly what you would do in JSON: make up a field for the purpose.

Though, honestly, that would seem to be the purpose of the "Link:" header.

Re:The Restful CookBook by JimDabell on Sunday May 24, 2015 @04:31PM (#9597469)
> What exactly is the criteria of being a "hypermedia capable format"?

One document must be able to link to another.

> Is there a predefined way to deal with it in XML?

Yes, Xlink:

http://www.w3.org/TR/xlink11/

> In the earlier example, I had assumed he did exactly what you would do in JSON: make up a field for the purpose.

The problem with this is that it's non-standard and nothing understands it that isn't custom-written for that particular API.

> Though, honestly, that would seem to be the purpose of the "Link:" header.

Yes and no. Although the Link header is useful, it's not part of the document, it's a transport layer header. REST is transport-layer neutral.

Re:The Restful CookBook by awinder on Sunday May 24, 2015 @05:07PM (#9597605)
There are a number of specifications that address linking in JSON:

  * JSON-LD http://www.w3.org/TR/json-ld/
  * HAL https://tools.ietf.org/html/draft-kelly-json-hal-06
  * Siren https://github.com/kevinswiber/siren
  * Uber https://rawgit.com/uber-hypermedia/specification/master/uber-hypermedia.html
Totally agree on the points against making up a field / format. Using standards where you can is a great way to bring familiarity & common tooling into your APIs. But don't focus too much on XML vs. JSON, use what you need / want, you can find a standard to support it.
Re:The Restful CookBook by jurre on Sunday May 24, 2015 @05:11PM (#9597630)
HAL solves this issue pretty well, doesn't it?
Re:The Restful CookBook by steveklabnik on Sunday May 24, 2015 @04:57PM (#9597558)
> which are not official standards

It depends on what you mean by 'official standards.' We've registered JSON API with IANA, so it's a standard media type, but there hasn't been an RFC yet, as we're basically just finalizing the spec now. (We're in a week-long period of just textual review, conceptually and structurally, it's done.)

And given that AMS is going into Rails and Ember Data will default to JSON API out of the box, hopefully we'll have enough usage to actually justify an RFC in a year or so.

Re:The Restful CookBook by petrbela on Monday May 25, 2015 @04:05PM (#9601514)
Great to hear that Steve!

We're actually moving towards the JSON API ~standard~ format and hope it becomes the standard that gets widely used.

Re:The Restful CookBook by steveklabnik on Monday May 25, 2015 @07:59PM (#9602252)
Neat! :) And thanks.
Re:The Restful CookBook by vdaniuk on Sunday May 24, 2015 @02:17PM (#9597024)
Are you aware about anything resembling a convention or at least a limited consensus of best practices combining JSON Schema/Api with JSON-LD? That would be immensely useful.
Re:The Restful CookBook by dhuramas on Sunday May 24, 2015 @03:51PM (#9597327)
"XML is bloated, almost no one uses it anymore." XML bashing is quite common these days. But I'd like to point out that it's the use case that matters when deciding between JSON and XML. Almost all "enterprise" software prefer XML over JSON.

https://www.quora.com/Markup-Languages/What-are-the-advantag...

Re:The Restful CookBook by collyw on Monday May 25, 2015 @04:30AM (#9599140)
I personally find XML more readable than JSON.
Re:The Restful CookBook by petrbela on Monday May 25, 2015 @04:20PM (#9601566)
I think a huge drawback of XML is it can't differentiate between an element and an array of one. So to "read" it correctly you should read a schema, too.