News for hackers. Stuff that matters.
Re:How to Design Better APIs by JimDabell on Saturday March 12, 2022 @12:13AM (#30649164)
Chrome, Safari, Firefox, Edge, and Opera are all third-party clients for the HATEOAS-based API known as the World-Wide Web.
Re:How to Design Better APIs by darkstar999 on Saturday March 12, 2022 @02:33AM (#30649693)
What?
Re:How to Design Better APIs by incrudible on Saturday March 12, 2022 @08:41AM (#30651261)
This answer is correct, but lacks context. REST wasn't conceived with APIs in mind. In fact, it's an awful fit for APIs, as many of the other comments point out. Rather, REST today is a buzzword that took on a life of its own, bearing only superficial resemblance to the original ideas.

HATEOAS is a generalization of how something like a website would let a client navigate resources (through hyperlinks). It requires an intelligent agent (the user) to make sense. Without HATEOAS, according to Roy Fielding, it's not real REST. Some poor misguided API designers thought this meant they should add URL indirections to their JSON responses, making everything more painful to use for those unintelligent clients (the code that is consuming the API). Don't do this.

If you must do REST at all - which should be up for debate - you should keep it simple and pragmatic. Your users will not applaud you for exhausting HTTP verbs and status codes. The designers of HTTP did not think of your API. You will likely end up adding extra information in the response body, which means I end up with two levels (status code and response) of matching your response to whatever I need to do.

If something doesn't quite fit and it looks ugly or out-of-place, that's normal, because REST wasn't conceived with APIs in mind. Don't go down the rabbit hole of attempting to do "real REST". There is no pot of gold waiting for you, just pointless debates and annoyed users.

Re:How to Design Better APIs by bluefirebrand on Saturday March 12, 2022 @05:58PM (#30655823)
Absolutely agreed on all points.

The best APIs I've ever used or built have been, at best, REST-ish.

And generally the parts where they deviate from REST make them more usable, not less.

Re:How to Design Better APIs by progval on Saturday March 12, 2022 @04:00AM (#30650076)
The web (HTTP + HTML + JS) intentionally fits the definition of a REST API. https://oleb.net/2018/rest/

In particular:

> The central idea behind HATEOAS is that RESTful servers and clients shouldn’t rely on a hardcoded interface (that they agreed upon through a separate channel). Instead, the server is supposed to send the set of URIs representing possible state transitions with each response, from which the client can select the one it wants to transition to. This is exactly how web browsers work

Re:How to Design Better APIs by brigandish on Saturday March 12, 2022 @06:39AM (#30650701)
The classic book on the subject is RESTful Web APIs[1], and it spends a while explaining HATEOAS by using the example of the web as we've come to expect it as the exemplar REST API using HATEOAS. I also have this essay[2] on HATEOAS in my open tabs, and it uses the example of a web browser fetching a web page.

[1] https://www.oreilly.com/library/view/restful-web-apis/978144...

[2] https://htmx.org/essays/hateoas/

Re:How to Design Better APIs by incrudible on Saturday March 12, 2022 @08:49AM (#30651332)
This should come with a big warning for people looking to do real work. This is not what most REST APIs are like in practice, nor what they should be. The vast majority of REST APIs are RPC-like, because that's the pragmatic way to deal with the problem 99% of the time. The "REST" branding is just for buzzword compliance.