|
|
|
|
|
by h2s
4610 days ago
|
|
There's a sliding scale of HATEOAS-ness. I've seen a much more extreme form of it described elsewhere. Mark Seemann (http://blog.ploeh.dk/2013/05/01/rest-lesson-learned-avoid-ha...) describes an approach that encrypts all URLs so that clients have no choice but to follow links because generating URLs from templates is impossible. So instead of http://foo.ploeh.dk/customers/1234/orders
You'd have http://foo.ploeh.dk/DC884298C70C41798ABE9052DC69CAEE
And you'd have to get that URL out of the response to another request you'd already made. I never liked this idea, and the linked article provides a really strong counterargument to this approach to HATEOAS. When browsing a website, decisions on what links will be
clicked are made at run time. However, with an API, decisions
as to what requests will be sent are made when the API
integration code is written, not at run time. Could the
decisions be deferred to run time? Sure, however, there isn't
much to gain going down that route as code would still not be
able to handle significant API changes without breaking.
|
|
But then again, I was just saying that the href attribute might make sense in some cases, with not much extra effort. Nobody is asking the clients to consume the href attribute, it just makes understanding the whole API easier.
As of images, what would make more sense, to add an endpoint /images/10/view or directly use an href attribute pointing to http://s.foo.bar/1337.png ?
My point is, in some cases it makes sense, just use it when it does. Just as one should not be encrypting URLs just because Mark Seemann feels it is within the holy grail of the Level 3 API as defined by Leonard Richarson [1], we should not be avoiding to make our APIs navigable.
[1]: Don't get me wrong. What they say might make sense in non-trivial APIs, as always, REST is not an specification.