Who Cares about GET vs. POST? NoREST
91–100 of 106 posts
Re: Who Cares about GET vs. POST? NoREST
#92Earlier quoted context omitted.
Why, are external developers able to consume restful APIs without the need for any documentation on the system they're talking to? Aren't the various REST entities (and all the possible links between them, if you're doing HATEOAS) already part of a protocol the developers of external consumers need to know beforehand?
I'm speaking from the experience of a developer who has built numerous public APIs and client libraries over the years. Yes, you still need documentation for a REST API (I'm not a HATEOAS utopian), but you can easily attach your documentation to concepts with which many (probably most) developers are already familiar. The article is basically saying "You know how lots of cars have steering wheels and pedals? Well, I…
In these days you have out-of-the-box so many already working API clients and already so many public API End-points that it would be really, really hard to create some ( opinionated ) better way of doing this.
Libraries like Backbone and platforms like NodeJS ( and many more ) have this idea so deep that it becomes extremely easy to create an API front-end / back-end app with just a matter of a couple of files ( even lines ). This is becoming standard in other platforms as well.
I think the debate is long time shifted from "Is REST good for my app?" to "How to best follow RESTful principles in my app?"
Re: Who Cares about GET vs. POST? NoREST
#93> Why not simplify by removing parameters from the URL altogether? Caching. Put a caching proxy in front of your api endpoint and enjoy. This is the same reason you'll want to do: /api/customer/1234/order/abcd instead of: /api?customer=1234&order=abcd Because even if your cache includes query strings (which it may, and you can configure it to), you lose order. Now you also have to configure your cache to ignore order…
urllib.urlencode(sorted(params.items()))Re: Who Cares about GET vs. POST? NoREST
#94Microsoft-stack developer doesn't understand how HTTP works. Film at eleven.
Re: Who Cares about GET vs. POST? NoREST
#95Earlier quoted context omitted.
> 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.
Then REST is a wrong word, one that doesn't point to a natural empirical cluster. The web is very different from all the other things that are called "REST API"s.
But that's because REST is often used as a buzzword by people who don't know what the architectural style entails, or aspirationally to describe one goal of the design of an API, but one that may be compromised for conflicting goals.
Re: Who Cares about GET vs. POST? NoREST
#96Is it just me or GET /customer/33245/order/8769 is wrong You have unique order id... then use it GET /order/8769 like that ??
Re: Who Cares about GET vs. POST? NoREST
#97Except that RPC-structured APIs are complete garbage to consume for external developers because, surprise, they don't know or care what your internal function names are. And if you aren't thinking about the experience of real or theoretical third-party developers when building your API, why even have one at all? If you ignore HTTP verbs and status codes you're just making it harder for other developers to grok your s…
> Except that RPC-structured APIs are complete garbage to consume for external developers because, surprise, they don't know or care what your internal function names are. And if you aren't thinking about the experience of real or theoretical third-party developers when building your API, why even have one at all? They don't care what the internal function names are but they do care about the language of the domain,…
I'm not sure of a domain where an operation cannot be represented as one of:
* Return $data
* Return a manipulation of $data that is the same type as $data
* Return a value derived from $data
* Update $data with a new value
* Create a new identifier with values that conform to the same type as $data
* Delete $data from the system
Certainly there are things like transcoding a streaming video which don't seem to map immediately, but they could if you shoehorned them. You're probably better off using something like UDP for that, though, instead of an HTTP request over TCP/IP.
Let's take images. Translation factor:
worzworts -> image (identity)
flubbleize -> encode to jpeg (non destructive manipulation)
mrefgle -> encode to png (non destructive manipulation)
chezzle -> execute image as a Piet program and return the output (derived value that is not necessarily of the same type)
Now, it's think through it a little. POST /image/ => 1
GET /image/1 -> identical response (except some http headers) to the imgur URL
GET /image/1/piet -> "Piet"
GET /image/1/jpeg -> /image/1 re-encoded as a jpeg
All good here. But let's look at some of the operations you suggest might be used, and the action they take: POST /image/1/jpeg -> re-encodes the gif as a jpeg and saves it to /image/1; does not conform to REST best practices because POST is for creating new records -- immediately the developer is confused
GET /image/1/piet -> because jpeg encoding is lossy, it fundamentally changes the data source at /image/1 with an arbitrary filter; in this case, JPEG compression.
Funky undefined behavior, and it may not have the side effects intended. Now let's see how it would work RESTfully: GET /image/1/jpeg -> returns a jpeg encoding of /image/1
POST /image/ -> 200 OK, { id: 2 }
POST /image/ "Piet" -> Error 415 (images expect an image, not a string)
GET /image/2 -> returns jpeg encoding of /image/1
GET /image/1/piet -> "Piet"
PUT /image/2 -> 200 OK
GET /image/2/piet -> "Piet" (since png is a lossless encoding, Piet will perform the same on it)
If you conform your API to single responsibilities, you won't confuse the consumers of it by transforming a data source in-place on their request.Things go a little sideways, but not much, if these operations need parameters. But that's why they're query parameters and not a part of the url. I don't think anyone would suggest that you create a URL like
/image/1/jpeg/width/640/height/480
That's just silly. If you follow the single-resource-deep philosophy, though, anything after the ID is a resource that is derived from the resource residing at #ID. This URL might actually make a lot of sense: /image/1/jpeg/resize/640x480
But then again, so would: /image/1/resize/640x480/jpeg
But wait, there's an even better way to define these ... and still be restful. /image/1.jpeg, /image/1.png, /image/1.piet
Oops, that last one doesn't work. Piet isn't an image format, it's the result of executing the image as a Piet program. So maybe that one works better as a URL segment: /image/1.jpeg (image), /image/1.png (image), /image/1/piet (string)
In this case, /image/1.jpeg?w=640&h=480
makes just as much sense as /image/1.png?w=640&h=480
But since we know that instead of a transformed image, the image/:id/piet resource is a derived string based on image/:id, this URL totally doesn't make sense - and neither should it! Should the image be resized before being executed? How exactly does one change the height of an ASCII string? Maybe you want an image of the ASCII string that has been resized? Ambiguous request! Undefined behavior! /image/1/piet?w=640&480 -> 400, bad request.
But these same operations could be done on a video stream. POST creates a new video stream identifier; streaming source opens a websocket/webrtc/whatever based on that identifier; GET /stream/1/hls -> hls chunked stream of the incoming source video; GET /stream/1/dash -> DASH chunked stream of the incoming source video. Uh oh, source stream disconnects due to a network glitch. That's okay, they can just re-open it with the same identifier. Source stream PUT /stream/1 : notifies the server that it is complete, server can cease to accept new streaming inputs for /stream/1; GET /stream/1/hls now returns a 301 redirect to /video/1/hls, which contains the entirety of the video that was streamed, as the server received it.Or do you have some other domain in mind that doesn't involve flubber?
Re: Who Cares about GET vs. POST? NoREST
#98Completely beside the point of the article, but just seeing a url like "/customer/33245/order/8769" makes me anxious that the author might give multiple customers the same order number.
If, in the particular domain, that makes sense, then so what? It may be that in this context, an "order" is only unique to a customer.
Re: Who Cares about GET vs. POST? NoREST
#99Microsoft-stack developer doesn't understand how HTTP works. Film at eleven.
I've been feeding my family and paying my mortgage using the Microsoft stack. God bless it. I also have never understood the REST mojo. I agree with the original poster. For my money, a url that resolves to a public API end point, with query string parameters to encode the arguments, is the most straightforward way to do RPC over HTTP I've used myself. When things get more complicated, as with an ajax client, then em…
As far as REST vs. RPC goes, there is a sole essential difference: the semantics of interaction with a REST resource are defined in RFC 2616, and a correctly designed and implemented REST resource behaves in accord with what you find there.
REST itself, meanwhile, being just HTTP, is very simple, and very well suited to expressing interactions with resources and collections of resources. Especially in the front-end/full-stack development world, most things can be expressed, with little or no semantic strain, as resources and collections of resources, and capable HTTP clients are highly available. (And the convention of encoding structured data as JSON in request bodies is very strong, besides.)
Conversely, there are as many RPC-over-HTTP standards as there are implementations; since doing RPC over HTTP necessarily means mapping whatever semantics you have in hand to an interface not designed to express them well, this makes headaches for people who have to develop against them, especially when writing an application that draws together many disparate APIs in order to do something interesting at their conjunction.
Whether REST is better than RPC over HTTP, or vice versa, strikes me as a question for a philosopher. But, in most cases of interacting with a remote resource over an HTTP transport, REST is certainly more natural, that is, closer to the native semantics of the transport, which results in thinner glue layers and more easily understood behavior.
Re: Who Cares about GET vs. POST? NoREST
#100Earlier 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 :)
Other than XML Schema, and XML namespaces, what was wrong with SOAP? Serious question. I genuinely think it had big advantages over REST.
The problem is that this does not actually help much in validating data sent or received. In addition, the client side SoapFooData you might receive is unlikely to be something that you want to pass around, so you still need wrappers for most complex structures.
Working with SOAP is complex even for extremely simple APIs, and for complex ones you will end up NOT using the generated objects anyway.
Finally implementations are generally buggy and incompatible with each other. And generated code is something that should be strongly avoided.
So in short: SOAP is complex and in return you get something that's pretty much useless (generated objects)