by samatman · 4y ago · 0 comments
How much of a verb doing what the verb suggests it does is up to the developer? The answer is 100%. Verbs provide no guarantees whatsoever, they're just an invisible thing that isn't in the URL.
Why is something like that an invisible thing that isn't in the URL, with no specified behavior?
Because it shouldn't exist is why.
I can understand the annoyance for there being so many verbs, but at the very least, there must be two: One that is guaranteed to be idempotent, and one that isn't.
Someone I know was trying to make a message board that was compatible with every browser. EVERY browser. Including Mosaic and Netscape 1.0. Which meant that everything was done using GET requests, including posting messages.
He changed his tune when some spidering engine found his site and issued tons of GET requests that ended up flooding the board with comments and posts that looked like web search queries.
OTOH, sometimes the best teacher is experience.
Instead there's a workaround for a serious problem, and any client (browser being by no means the only client) which doesn't respect the convention can emit identical POSTs, with no way of knowing if that was intended.
I would probably be in favor of some more strict guards around specific verbs, but I don't really know how that would be implemented given that the behavior is always controlled by the developer at the end of the day.
Web frameworks adhering to these conventions is probably a good thing, though, and in my somewhat limited experience, that seems to generally be the case (though they often still let the developer override the behavior).
Redirects are done in js, 404s are just normal pages, if that, and 401s are just not a thing on the public web anymore.
301s can be somewhat handy in certain circumstances too.
Redirects definitely happen in more places than you think/see, mostly because almost all tooling handle redirects transparently to the user, so you don't really notice it.
Doing redirects in JS is a huge waste of resources as well, as you'll need to load a full page with it's body (meaning the browser will parse and execute it) while having a 301 + Location header means the browser can redirect quicker without executing more stuff.
"An HTTP GET request includes request header fields and no payload body and is therefore transmitted as a single HEADERS frame, followed by zero or more CONTINUATION frames containing the serialized block of request header fields."
https://www.rfc-editor.org/rfc/rfc7540#section-8.1.3 (HTTP/2.0)
"A payload within a GET request message has no defined semantics; sending a payload body on a GET request might cause some existing implementations to reject the request."
https://www.rfc-editor.org/rfc/rfc7231#section-4.3.1 (HTTP/1.1)
I've never used one or spec'd one, I consider it unsafe.
This is, of course, what the specs say, and they don't even really agree; I am well aware of the non-trivial daylight between "what the specs say" and "what happens in the real world". I point this out not as a spec compliance maniac but as something people ought to know... it's not a great plan to expect GETs to be able to have bodies, just as I would not suggest sending a 404 response code that also has the "real data" in it for whatever reason. You're just asking for trouble, even if it might sometimes work.
Do you mean to suggest that you advocate for an everything-is-200-OK design and the client should be checking for an error object there?
The angst around GET verbs is that someone could really be doing an update if it has a body. Well guess what, someone can be doing an update based purely off the query string too.
This angst around GET bodies is rules lawering AT BEST. It's the type of distinction that has no real merit and I consider it an absolutely short-sighted decision by the OpenAPI Spec to insist that GET has no body (they've recently changed this, but I can't believe it was ever a thing. Finally some common sense).
---
TO BE VERY CLEAR:
Back in the day you would hear stories of companies getting entire sets of data wiped out from a search engine bot that was happily following GET requests that would delete data.
There is absolutely nothing in a GET request that guarantees anything except what the developer decides to guarantee. That a developer SHOULD choose that a GET request be idempotent is still a choice regardless of the existence of a body or not.