Re:Ask HN: Suggestions for books about API design?
by pixelmonkey on Saturday September 05, 2020 @11:34AM
(#24384309)
Yes, honestly this was written at a time when browsers (specifically, the XHR API) did not support non-GET requests reliably at all (e.g. pre-CORS), so there was no other option. (And once you publish an API, it's hard to change.) You're right that today there is better support for POST/PUT, although there might still be some issues lurking in the corners.
Re:Ask HN: Suggestions for books about API design?
by pvg on Saturday September 05, 2020 @11:42AM
(#24384361)
I don't think there's ever been a time browsers haven't reliably supported POST.
Re:Ask HN: Suggestions for books about API design?
by pixelmonkey on Saturday September 05, 2020 @12:46PM
(#24384922)
In a cross-domain context, when you are expecting the browser to make its XHR for JSON data via JavaScript to a third-party API. Think about making a call to the Flickr.com HTTP API from your own WordPress myblog.com domain. In that context, the XHRs didn't support POST/PUT. Remember, even the fetch() API is pretty recent. POST-based forms are irrelevant for API usage.
This MDN doc covers some of the complexity:
https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS
And here is when browsers added support for CORS:
Re:Ask HN: Suggestions for books about API design?
by 082349872349872 on Saturday September 05, 2020 @12:36PM
(#24384848)
I dimly recall a pre-form web, but it could easily be they just took over a little-used Berners-Lee verb. (For instance, PUT support was atrocious for a while.)
Re:Ask HN: Suggestions for books about API design?
by pixelmonkey on Saturday September 05, 2020 @12:55PM
(#24384988)
This is not about pre-form web. It's about pre-CORS web. Which is pretty recent web. CORS was "widely & properly" supported by "recently released" browsers around 2012-2013. Of course it's only as of very recently that you could safely assume 2010-2013 browser versions were completely out of circulation.
Re:Ask HN: Suggestions for books about API design?
by 082349872349872 on Saturday September 05, 2020 @01:05PM
(#24385082)
My bad; hadn't parent'ed enough, and the "using different methods than GET" clarification would not have been anachronistic even in the previous century.
Re:Ask HN: Suggestions for books about API design?
by karlshea on Saturday September 05, 2020 @01:49PM
(#24385445)
PUT can still be weird. For example, PHP doesn't process multipart/form-data if it's a PUT instead of a POST, I'm working on an API in Laravel and for methods that need to PUT a file I have to use Laravel's _method spoofing.
Re:Ask HN: Suggestions for books about API design?
by alezha on Saturday September 05, 2020 @10:50PM
(#24388587)
Agreed about the idempotency concern. Safari for example will sometimes make past GET requests while making a current GET request, so you can get oopsied if you put a non-idempotent request in a GET.
On the other hand, if multi submitting causes bad behavior, a failsafe should probably be baked in to the endpoint logic itself rather than relying on POST not being abused.
Using different methods than GET is easy in the browser (easier than JSON-P) and avoids a huge class of problems that come with abusing GET.