Who Cares about GET vs. POST? NoREST
61–70 of 106 posts
Re: Who Cares about GET vs. POST? NoREST
#62Earlier quoted context omitted.
There's no WSDL or .thrift -equivalent for discovery, and no autogenerated client code which makes use harder. Getting up and running is slower because you have no way to validate that your messages are well-formed short of throwing them at the server and seeing what it sends back. What criteria are you seeing REST as better on?
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.
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 expressed as XML, you can do much better.
Re: Who Cares about GET vs. POST? NoREST
#63Pure 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…
In my opinion REST is fat more easier to understand for non-CRUD resources. The whole idea of CRUD makes REST sometimes seem like an HTTP adapter to the database.
However, when you move beyond these simple examples and start trying to build a REST API for a messy, complex system, you immediately run into trouble. How do you deal with non-CRUD operations? How do you deal with long running processes?
You POST the work to be done to a resource. That resource returns a URL where you can follow the state of the long running process. An alternative would be to provide a Webhook that will be called when the long running process has finished.
Or entities in an indeterminate state?
Same principle, return its actual state on a GET request (polling). Or use a Webhook (push).
How do you aggregate multiple resources into individual request/responses for performance?
Use HAL embedding or multipart.
How do you de-duplicate identical entities within an aggregated response?
Use the hypertext caching pattern in your caching layer or proxy. Use the URL as a unique key.
How do you return only particular fields?
Use HAL embedding, query parameters or a subresource.
How do you handle paging and filtering?
Use link relations and query parameters.
How do you handle transactions?
That's exactly what POST is for.
How do you handle authentication and security restrictions?
Provide a token header over https. Avoid magic URLs based on cookie state (i.e. even when you are logged in as mike your account details still are at https://example.org/user/mike/account). Restrictions are a product of the token and the requested URL.
All of these things can be solved, but by the time you've finished, your API will be far from easy to understand.
That is true, it won't be easy to understand, but it will be simple, composable, discoverabe and scalable.
It will need a load of accompanying documentation to make it usable
In my experience the opposite is true, true REST (which includes hypermedia controls) need less accompanying documentation. It makes resources more predictable and less dependendent on URLs.
All of these things can be solved, but by the time you've finished, your API will be far from easy to understand. It will need a load of accompanying documentation to make it usable, and will have a bunch of weird corners where you're initiating operations as a side effect of setting entity flags, or you've noun-ed verbs in order to turn an abstract operation into a resource. E.g. PUT /server-reboot-attempt.
In stead of making a separate resource for every action it would suffice to make one that receives actions by POSTing to it. You can respond with a URL that represents its progress. And it will also save a lot of unnecessary links or hardcoded URLs.
Re: Who Cares about GET vs. POST? NoREST
#64Following the REST patterns means you can take advantage of things like standard agnostic intermediaries for caching & filtering. You can switch or even spread across service providers by changing domain names in URLs. You can mitigate network issues through guaranteed idempotence and using conditional headers like if-none-match. These are all issues that you'll probably have to rediscover and re-solve on your own, if your API lives long enough.
It is not about SEO or visually "clean" URLs. REST says nothing about that, despite many misconceptions otherwise. In fact, in a truely RESTful service, resource URLs can be obscure garbage like http://example.com/A13D-DE45-32BC. If you're using the HATEOS principle, those URLs will be picked up from links in your responses.
"Pidgeonholing" your errors to standard HTTP error codes means that you've followed a shared standard, rather than inventing your own from scratch. Also, 4xx errors generally refer to something in the client's request, while 5xx errors generally mean something has gone wrong while generating a response on the server side.
If you don't need any of these things - because, say, you're building an API that will only be used between two parts of your own small system - then don't worry about REST. Go ahead and build something along RPC lines.
You might regret it someday, if you find yourself needing the scaling characteristics of the WWW. But, many systems never grow to that point anyway.
Re: Who Cares about GET vs. POST? NoREST
#65It would have been nice if he proposed something innovative moving forward, but this is a step back to RPC-structured APIs. After reading this though, I had to check to make sure it wasn't April 1st.
I think the whole point the article is trying to make is that REST isn't really a step forward from RPC. It just adds an overly restrictive taxonomy (i.e. in a complex practical application, you're probably going to run into a problem that doesn't fit the REST model well), and doesn't actually solve any real problems.
Re: Who Cares about GET vs. POST? NoREST
#66Earlier quoted context omitted.
> advocating abandoning it completely in favor of RPC-over-HTTP It surprises me that the author didn't go one step further and ask us to return to SOAP :)
I think that we're only a few years away from someone reinventing SOAP but with JSON playing the role of XML.
Re: Who Cares about GET vs. POST? NoREST
#67I am increasingly getting irritated with REST for our app. It takes too much thought to figure out the "correct RESTful approach" when building out an API endpoint. And then again, there are no right answers. And all the JSON serialization/de-serialization logic, for every single endpoint. Too. Much. Work. I'm wondering why Thrift/Proto-buffers aren't popular? Even for browser-based JS clients. What're the pitfalls?
Re: Who Cares about GET vs. POST? NoREST
#68Pure 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…
Re: Who Cares about GET vs. POST? NoREST
#69Earlier quoted context omitted.
> People right on HN spend their time arguing over what is restful and what isn't ,because vague "semantics". The defined semantics of HTTP/1.1 methods ( REST is a style, but HTTP/1.1 is a standard) are not vague. > And to be frank, if you're not using HATEOAS , there is very little difference between a api with beautiful urls and a few headers and rpc. If you aren't using HATEOAS, you aren't using REST. That doesn't…
> 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…
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 at it from the other direction. Or, don't try wrestling with REST.
Re: Who Cares about GET vs. POST? NoREST
#70Pure 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…
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…