Who Cares about GET vs. POST? NoREST
swaxblog.tumblr.com
swaxblog.tumblr.com
The problem with
> If you think some of the arguments of the article were made poorly, point them out and say why.
Is that the linked article is fractally wrong. It's not so much that it has bad arguments, it's that there's more or less nothing which is correct in the article, and trying to reply to a specific incorrect statement only brings more incorrections, recursively, ending up with a tentative response which is longer than the original post by an order of magnitude.
The core issues are these: the author has no understanding whatsoever of REST (which I guess they can hardly be faulted for, since few people care to understand it), and is reinventing RPC-over-HTTP (badly and apparently with no awareness that it already exists).
There is a specification for web requests which works rather well, is relatively applicable for any resource oriented service, and has well defined semantic conventions/specifications for failures, operations on resources, and responses to operations. It's an incredibly well known & understood specification. Any things you wonder have almost certainly been asked a thousand times before, and a single Google search will invariably land you on Stack Overflow with a productive discussion about what the best approach is.
Why not make use of this? You lose nothing by generally following the standard (since you can deviate from them whenever you need), but you gain so much - both from the perspective of building your API, and from the perspective of a potential person using your API.
---
Also two things specifically came to mind to mention:
> Who Cares about GET vs. POST?
There are very practical implications from the use of GET/POST. Any GET request you support can be called from any website without any knowledge from the user. For example:
<img style="display:none" src="https://example.com/user/setPassword?password=foobar" />
By using a POST, along with standard cross origin protections, it is much more difficult for a malicious website to have any impact on your user. (Although CSRF checking should be done anyway)"Well then, I'll just use POST for everything", you might say. There are a great number of downsides for that also: preventing caching, not allowing cross-origin communication without CORS, clients not being sure about idempotency, etc.
---
> "If we put the function name between the parameters themselves"
I found this interesting, because there is a language which does this - Objective C.
These are fairly equivalent:
GET /customer/getOrder?customerID=33245&orderID=8769
customerGetOrder(33245, 8769)
And these are equivalent, but oriented the 'RESTful' way: GET /customer/33245/order/8769
[self getOrder:8769 forCustomer:33245];
Customer.find(33245).orders.find(8769);
Personally I think the latter examples work much better in a resource oriented service. They show logical structure, relationship between objects, etc.So yes informal sloppy REST is commonly used and there is some virtue in that, but as any REST advocate will attest to, sloppy informal REST has its drawbacks, as Dropbox found out. Moving to a more formal REST architecture may solve those problems, but you lose the "commonly-used" virtue.
Add to that the problem that when you have application logic that is not REST-like, forcing it into REST can require a convoluted middle-layer. Avoiding that complication is worth well more than "commonly-used"
I like REST in general, and I even think formal REST with its many HTTP verbs and HTTP headers has a formal elegance. But there are plenty of reasons to go in a different direction, if your application logic favors a different way.
Take this to its logical conclusion, and you end up with "http://mywebsite/getUserProfileFirstAddress" when you want an endpoint that just returns the first address (or you end up with lots of stuff in a query string that ends up becoming a quasi-programming language), as opposed to a "restful" way of doing it, "user/1/profile/address/1". It's not so much about being readable for computers, we can solve that problem, it's about being readable for humans, which is the harder problem to solve.
Your comment is great though. That's all people really want when they say REST (most people, anyways). It's codeword for "please don't use SOAP or otherwise make your API extra hard to use".
Anecdotally though - I find "restful" APIs much easier to parse and comprehend by eye than the old SOAP/Contract method.
More importantly, REST created a relatively clean and clear API that almost anyone can understand for any service. Sure, it does vary, as it is not "standard", and every site has their own resources and paths, but the learning curve to a new API is dramatically lower.
As far as ease of use I certainly don't find it any easier to write clients that need to put parameters in the URL, headers, and in the body. And I've still gotta look at the documentation and most likely write a small client wrapper in most cases.
Elasticsearch comes to mind, and actually, REST has only hurt my use of it, because simple typos that would cause errors otherwise now have meaning. Eg DELETE /index/type/id when id is empty deletes a whole type. Whereas with RPCish, I'd be calling a "deleteDocument" method so no id just means failure. Also, it's lots of fun when your document id doesn't encode well into the URL, like containing / or must-encode chars. So again, what's the benefit I'm gaining here?
HTTP is fantastic cause it gives apps an easy client server wrapper for making TCP requests, along with some usable spots for request info and metadata. And as a bonus, GET vs POST lets us indicate a call might be read-only. Cramming APIs into some guys thesis on how HTTP should be used seems as weird as people that enjoy needlessly applying OO patterns to code.
Except in REST, a resource would not be identified by an array. If the resources would be a list and you would want to filter it, you would indeed use query parameters.
I do not see that the article brings up valid concerns at all. It seems to me, that the author just wants to simplify something, which is already quite nice and simple.
REST is a common standard, that fits nicely on top of HTTP. Why not use standard error codes if they are already available and commonly known? Isn't that the whole point about standards, that people know them and are therefore already better informed without knowing your specific implementation?
I understand criticism against religiously following standards when they are hard to implement or the benefit is marginal. I for example get, using cookies for authentication of an internal API.
I don't see the point of restricting myself to POST and 200/500 error codes, the extra work here to conform to REST is minimal while the benefit to the consumer is clear.
If you do things in this manner, everyone who has to deal with your API will have a good understanding of how it works. Even people who've never studied REST will have a good idea of how it works, as long as they are familiar with the web in general.
JSONRPC can save you a lot of headaches, and hardly imposes any restrictions on how you roll your api itself.