Live data from Hacker News

How I learned to stop worrying and love REST

mikemayo.org

11–20 of 38 posts

Re: How I learned to stop worrying and love REST

#11
post #4
post #2

Disclaimer: I do not want to steal the author's page views, but I could hardly read this article, due to the white shadow in the Text. Here is a more readable view: http://rdit.in/5c

In Chrome I do right-click, inspect element. Then I CSS the shadow away :)

Just because you can, doesn't mean you should (have to).

Re: How I learned to stop worrying and love REST

#13

What is the HATEOS compliant way of accepting parameters? E.g. for the pagination example, you might want to let the consumer specify number of entries pr. page, or you might want to accept a search-term or limit by period.

An HTML form could be one way of doing this. As long as the API complies with the form it sends out.

However, getting a client to automatically understand this is a little harder.

You could approximate a form in JSON, which would be similar in structure to its HTML counterpart.

Re: How I learned to stop worrying and love REST

#14

What is the HATEOS compliant way of accepting parameters? E.g. for the pagination example, you might want to let the consumer specify number of entries pr. page, or you might want to accept a search-term or limit by period.

The HTML form tag; also expressed more directly as URL templates. The server provides the parameterized template, and the client fills in the params to access the resource.

Re: How I learned to stop worrying and love REST

#15
post #13

What is the HATEOS compliant way of accepting parameters? E.g. for the pagination example, you might want to let the consumer specify number of entries pr. page, or you might want to accept a search-term or limit by period.

An HTML form could be one way of doing this. As long as the API complies with the form it sends out. However, getting a client to automatically understand this is a little harder. You could approximate a form in JSON, which would be similar in structure to its HTML counterpart.

This is such a fundamental problem that I am surprised that there is not a definitive answer.

Re: How I learned to stop worrying and love REST

#16

What is the HATEOS compliant way of accepting parameters? E.g. for the pagination example, you might want to let the consumer specify number of entries pr. page, or you might want to accept a search-term or limit by period.

Query parameters create hyperlink templates.

So

    href="foo/bar/?baz=x"
is really a way for generating a set of hyperlinks that range over whatever domain x comes from and the client should feel free to plug in any valid value for x. You can even indicate the domain of x by returning a 405 in the case of an invalid value (although it would be nice to have a standard way of indicating the domain beforehand)

For instance, if there are 10 pages then x ranges over [1-10]. If the client request ?page = 11 then we'd return a 405 error indicating that the only valid values are [1-10].

Re: How I learned to stop worrying and love REST

#17

What is the HATEOS compliant way of accepting parameters? E.g. for the pagination example, you might want to let the consumer specify number of entries pr. page, or you might want to accept a search-term or limit by period.

I think you should have a pagination resource that understands a resource and returns a paginated URL.

it would accept parameters. I think having a template requires the client to understand a format other than hypertext.

Re: How I learned to stop worrying and love REST

#18

This is probably my number one criticism of most "REST" APIs out there - they are horribly non self-documenting, and the effort required to make them self-documenting is really fairly trivial: 1. Ensure that you have a URI to the resource in question every single time you reference an ID somewhere (in collections, when referencing resources from another resource) 2. Make the root of your application document all the…

Yes, what you describe is true. We also had a good discussion a few days ago about scenarios where REST doesn't seem to work well. The specific problem is when things start getting too chatty. Its very difficult to expose a flexible (fine-grained) REST API and at the same time give you all the data you need in the least amount of calls. It takes quite a bit of work up front to figure out what your model is going to be and figuring out if that model will work for most of your consumers. Getting the 'pattern' down as you described is half the battle.

http://news.ycombinator.com/item?id=3538585

http://news.ycombinator.com/item?id=3538134

Re: How I learned to stop worrying and love REST

#19
post #6

I hate when people try tell me REST isnt the way to go. I guess if you're an out-dated organization with a lot of time (and money) on your hands, you could stuff around with something else...but why would you in this world as a startup do anything else? Nice article, i think the world needs a very basic "this is how you use REST" bullet point style blog post somewhere. This lesson would be 1 of those bullet points if…

>why would you in this world as a startup do anything else?

Because the tech's immature and irrelevant to your core competency? The paragraph at the end of the HATEOAS page sums it up pretty well for me - and seems to be struggling to make the case for the benefits of "full REST". I despise the enterprisey verbosity of SOAP et al, but given the choice between an inefficient but well understood standard with good tooling support and the new hotness that no-one quite understands properly yet...

Re: How I learned to stop worrying and love REST

#20

What is the HATEOS compliant way of accepting parameters? E.g. for the pagination example, you might want to let the consumer specify number of entries pr. page, or you might want to accept a search-term or limit by period.

Query parameters create hyperlink templates. So href="foo/bar/?baz=x" is really a way for generating a set of hyperlinks that range over whatever domain x comes from and the client should feel free to plug in any valid value for x. You can even indicate the domain of x by returning a 405 in the case of an invalid value (although it would be nice to have a standard way of indicating the domain beforehand) For instance…

I find URL templates smelly. Once you stick a place holder in the URL, it's no longer a valid URL - it's something that requires custom mangling before it can be passed along.

In your example, I need to know that the x is something that requires replacement. How is that fundamentally different from just putting in your documentation (and, in the 405 if not passed) "this resources takes query param baz" - which is not HATEOS?

Also, this doesn't cover the case of optional parameters. Specifying optionality in a template is horrible (something like "bar/?baz=x[&ogle=y]" to borrow the pattern from man pages), and specifying individual URLs for each combination of parameters is impractical for more than a few.

Post reply on HN