Live data from Hacker News

Who Cares about GET vs. POST? NoREST

swaxblog.tumblr.com

71–80 of 106 posts

Re: Who Cares about GET vs. POST? NoREST

#71
post #70
post #63

Earlier quoted context omitted.

Pure REST is great for toy examples, where every domain entity fits neatly into a resource and every operation is a CRUD one that can be represented as an HTTP verb. So there is a million tutorials explaining how to build a REST API for a blog with BlogPost and Author resources, or an ordering system with Customer and Order resources. In my opinion REST is fat more easier to understand for non-CRUD resources. The who…

Any book / link where you think we can get more details about your responses?

Most O'Reilly books about REST are really good. If you want to be more practical I suggest looking for simple ways to introduce hypermedia controls. In my opinion the HAL JSON standard is the easiest to understand: https://www.google.com/search?q=hal+json

Re: Who Cares about GET vs. POST? NoREST

#72
post #62

Earlier quoted context omitted.

HATEOAS provides both discovery and, when well-known content types are used, potentially much richer ready-to-use client code than the autogenerated host-language interfaces provided by SOAP and similar protocols.

HATEOAS only lets you discover something by going there, so to speak; it doesn't give you a complete index like a WSDL. At the transport level you get much richer and more structured client code from SOAP. Automated HATEOAS clients are at this point purely theoretical, and anything you could put a content-type on and send over HATEOAS you could equally embed in a SOAP response. If the thing you wanted to embed can be…

Your browser is an "automated HATEOAS client". You can toss it any old HTML doc and it knows what to do with things described in the HTML content-type spec such as links, forms, images, scripts, etc.

Re: Who Cares about GET vs. POST? NoREST

#73
post #62

Earlier quoted context omitted.

HATEOAS only lets you discover something by going there, so to speak; it doesn't give you a complete index like a WSDL. At the transport level you get much richer and more structured client code from SOAP. Automated HATEOAS clients are at this point purely theoretical, and anything you could put a content-type on and send over HATEOAS you could equally embed in a SOAP response. If the thing you wanted to embed can be…

Your browser is an "automated HATEOAS client". You can toss it any old HTML doc and it knows what to do with things described in the HTML content-type spec such as links, forms, images, scripts, etc.

No, the browser is very much a manual HATEOAS client.

Re: Who Cares about GET vs. POST? NoREST

#74
post #62

Earlier quoted context omitted.

HATEOAS provides both discovery and, when well-known content types are used, potentially much richer ready-to-use client code than the autogenerated host-language interfaces provided by SOAP and similar protocols.

HATEOAS only lets you discover something by going there, so to speak; it doesn't give you a complete index like a WSDL. At the transport level you get much richer and more structured client code from SOAP. Automated HATEOAS clients are at this point purely theoretical, and anything you could put a content-type on and send over HATEOAS you could equally embed in a SOAP response. If the thing you wanted to embed can be…

> HATEOAS only lets you discover something by going there, so to speak; it doesn't give you a complete index like a WSDL.

HATEOAS doesn't inherently require that you "go" anywhere to get a hypertext document describing an API, and can be as complete as you want. But, since its really designed for web-scale decentralized interlinked APIs, no, its not primarily intended to have one document that gives you every possible linked endpoint.

> Automated HATEOAS clients are at this point purely theoretical

Googlebot is an example of an automated HATEOAS client that handles a wide array of content types. It is decidedly not purely theoretical.

Re: Who Cares about GET vs. POST? NoREST

#75
post #58

Earlier quoted context omitted.

> If you aren't using HATEOAS, you aren't using REST. Then almost no REST api i've seen out there the is a REST api,which is my point exactly. If you're writing a spec almost nobody understands and almost nobody truly implements yet everybody think they implement, then you failed at writing that spec. Because I can guarantee you out there a only few people understand HATEOAS. And that's the heart of the problem. The…

Everyone writing a web page with links you can click on to navigate through a web site understands HATEOS. It's just that, for some reason, when you shift to imagining a robot interacting with your site rather than a person, people get confused. Though, really, I know that the reason is that they're trying to shoehorn an existing set of APIs into this cool REST thing they've heard about. In reality, you need to look…

[deleted]

Re: Who Cares about GET vs. POST? NoREST

#76
post #30

Earlier quoted context omitted.

Sure, that sounds nice in theory. In the wild, how many developers (especially those working on internal APIs) have the time & inclination to thoroughly document their entire APIs? And if it exists, many developers read the entire spec of an API before beginning development? In my experience both are rare. Given the constraints developers often find themselves under, having an API that uses common patterns most devel…

Note that this use of conventional URI structure patterns does have the value you describe, but is also completely orthogonal to REST (REST isn't about beautiful URIs -- the path part of the URI could all be UUIDs and you could follow the REST architectural style perfectly; HATEOAS, in particular, means that other than the entry point, your URIs should all be coming to you from other documents with their context in t…

Yes, there is a difference betwixt 'true REST' (as defined by Roy Fielding in his PhD dissertation) and what most people refer to as REST. I was referring to the latter: in my experience 'true REST' APIs are rare in the wild.

Re: Who Cares about GET vs. POST? NoREST

#77
post #62

Earlier quoted context omitted.

HATEOAS only lets you discover something by going there, so to speak; it doesn't give you a complete index like a WSDL. At the transport level you get much richer and more structured client code from SOAP. Automated HATEOAS clients are at this point purely theoretical, and anything you could put a content-type on and send over HATEOAS you could equally embed in a SOAP response. If the thing you wanted to embed can be…

> HATEOAS only lets you discover something by going there, so to speak; it doesn't give you a complete index like a WSDL. HATEOAS doesn't inherently require that you "go" anywhere to get a hypertext document describing an API, and can be as complete as you want. But, since its really designed for web-scale decentralized interlinked APIs, no, its not primarily intended to have one document that gives you every possibl…

Googlebot is not an automated HATEOAS client, it's solely an automated web client. Even if the web conformed to all the specifications it would still be an exceedingly atypical example of a HATEOAS API. And googlebot is nowhere near the reliability level that we would require for most use cases.

Re: Who Cares about GET vs. POST? NoREST

#78
post #73

Earlier quoted context omitted.

Your browser is an "automated HATEOAS client". You can toss it any old HTML doc and it knows what to do with things described in the HTML content-type spec such as links, forms, images, scripts, etc.

No, the browser is very much a manual HATEOAS client.

Incorrect. When you view a html page, the browser fetches the javascript, css and images in the page automatically.

Re: Who Cares about GET vs. POST? NoREST

#79

Pure REST is great for toy examples, where every domain entity fits neatly into a resource and every operation is a CRUD one that can be represented as an HTTP verb. So there is a million tutorials explaining how to build a REST API for a blog with BlogPost and Author resources, or an ordering system with Customer and Order resources. However, when you move beyond these simple examples and start trying to build a RES…

> How do you deal with non-CRUD operations?

There is no such thing as a non-CRUD operation in a well-modeled domain. Actions in the domain are entities in the model and, therefore, are subjects of CRUD operations (often just Create and Read, but Update and Delete can also be sensible.)

> How do you deal with long running processes?

As entities that can be Created and Read.

> Or entities in an indeterminate state?

By returning a representation of the applicable wavefunction.

> How do you aggregate multiple resources into individual request/responses for performance?

By defining resources that are aggregates of other resources, and including, among the available representations for such resources, representations that include the subelements directly rather than only by reference.

This is analogous, in the RelationalDBs, to defining views (or set-valued functions, depending on the type of aggregation you are doing.)

> How do you de-duplicate identical entities within an aggregated response?

Whether or how you do this depends on the representation chosen.

> How do you return only particular fields?

By returning a representation that includes only the projection of the base resource that is of interest. I suspect the question you mean to ask, however, is how you specify a request for such a projection in REST over HTTP (REST is not tied to a particular protocol, but HTTP is the most popular one used with the architecture, and does have some particular issues in this particular case), and there are a couple of obvious alternatives:

1) Treat this as a request to create a subordinate resource to the base resource, and do it via POST, or 2) Recognize that this (like the use case met now by PATCH) is a gap in the existing HTTP method set that requires a workaround, and add a HTTP extension method (preferably, one proposed as an RFC with general semantics), such as something similar to WebDAV's REPORT or SEARCH (but not so application-specific.) REST doesn't -- with an extensible protocol like HTTP -- mean you have to be limited by the base protocol, it just means you have to be judicious in your use of extensions. [0]

> How do you handle paging and filtering?

Same answer as the previous question (in fact, paging and filtering are essentially the same thing as the previous question.)

> How do you handle transactions?

A unit of work that is logically linked in the domain is an entity in the domain that can be Created, Read, Updated, and Deleted (particularly C = BEGIN , U = COMMIT, D = ROLLBACK.) Actions within the transaction can either reference the transaction in resource representations or be subordinate resources to the transaction itself, depending on context.

> How do you handle authentication and security restrictions?

Generally, Authentication is communications-protocol dependent and how security restrictions are enforced is outside of the scope of REST.

[0] http://roy.gbiv.com/untangled/2008/rest-apis-must-be-hyperte... : "A REST API should not contain any changes to the communication protocols aside from filling-out or fixing the details of underspecified bits of standard protocols, such as HTTP’s PATCH method or Link header field."

Re: Who Cares about GET vs. POST? NoREST

#80
post #77

Earlier quoted context omitted.

> HATEOAS only lets you discover something by going there, so to speak; it doesn't give you a complete index like a WSDL. HATEOAS doesn't inherently require that you "go" anywhere to get a hypertext document describing an API, and can be as complete as you want. But, since its really designed for web-scale decentralized interlinked APIs, no, its not primarily intended to have one document that gives you every possibl…

Googlebot is not an automated HATEOAS client, it's solely an automated web client. Even if the web conformed to all the specifications it would still be an exceedingly atypical example of a HATEOAS API. And googlebot is nowhere near the reliability level that we would require for most use cases.

> Even if the web conformed to all the specifications it would still be an exceedingly atypical example of a HATEOAS API.

The HTTP-powered Web is the prototypical REST (including the HATEOAS constraint that is part of the definintion of REST) API.

Post reply on HN