Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

The only actual benefit I've ever been able to come up with for HATEOAS / "true" REST, is that it allows servers to evolve independently from clients. As in, you can change endpoints under the hood, but as long as the names of the hypermedia controls stay the same, the client doesn't actually need to change. That is, it's just a level of indirection based on names.

What I'm looking for someone to answer is, when I control both the client and server, why is this a benefit?



REST as understood by Fielding is useful when you have a highly heterogeneous, connected set of things your clients and servers operate on, like websites or a government intelligence system.

These sorts of domains are pretty uncommon. It's far more than just an extra layer of indirection to keep backwards compatibility; in practice, you can't change HTTP-layer APIs regardless of your hypermedia controls. People bookmark things and write curl scripts.


I'm not entirely sure. Fetching attributes of related entities and pagination are really common operations, and those are natural cases where providing the client with pre-built URLs can make the client's job a lot simpler.


A few benefits of the hypermedia approach are:

- It can be a much simpler approach to building an application. As evidence for this fact, consider Contexte's experience moving from react to htmx for their Saas application: https://htmx.org/essays/a-real-world-react-to-htmx-port/. They reduced their codebase to 1/3rd the size with no reduction in UX, dropped JS dependencies by 95%, etc. Not every project is this amenable to hypermedia, but many are.

- Related to this, hypermedia is the "native" architecture of the web, and browsers have a lot of technology built into them for it. htmx is a depenedency-free 12k library because it builds on top of that model.

- By adopting hypermedia as your system architecture, you push your logic back onto the server side, where you are free to use whatever programming language you prefer: clojure, python, haskell, etc. This lets you write more code in your preferred programming language and execution environment.

- The server side is a trusted computing environment, so you can have complete access to a data store when writing logic there. This is in contrast with the browser, where you can't have unrestricted access to the data store due to the fact that a hostile user can open a console and start manipulating the data store. On the server side, you can just use SQL. On the client side, you can't, without putting your whole data store at risk.

There are certainly tradeoffs associated with the hypermedia approach: it doesn't work well in situations when you need to respond quickly to many UI-driven events, it sacrifices representational efficiency for flexibility, etc. There isn't a silver bullet, after all.

With htmx I am trying to expand the set of applications for which the hypermedia approach will work, but I have no illusions that it will work for everyone: nothing is right for everything.


> It can be a much simpler approach to building an application

This is not related to hypermedia, this is related to server-rendering vs. client-rendering. Everyone knows that server-rendering saves on some code and JS. This is a tradeoff, for less control over the stateful aspects of the client.

> Related to this, hypermedia is the "native" architecture of the web

But, that was the text-based web. Hypermedia isn't necessary (or desired) for applications, which the web has moved towards supporting.

> By adopting hypermedia as your system architecture, you push your logic back onto the server side

Nothing to do with hypermedia. You can choose to push logic to the server with a single-page app too.

> The server side is a trusted computing environment, so you can have complete access to a data store when writing logic there

Same.

I'm still failing to see a _benefit_ that hypermedia and HATEOAS approach provides, or what problem it solves.


> What I'm looking for someone to answer is, when I control both the client and server, why is this a benefit?

If you (and only you, personally) control both the client and the server (and by "control" I mean you can update/deploy them as you please, simultaneously if necessary), you can feel free to use any sort of homebrew efficient binary stateful protocol and format you like, with no consequence.

However, the more parties that are involved (co-workers, separate teams, external organizations, etc.), and the less those parties are able/willing to synchronize their efforts over time, the more benefit you will see from aspects of REST and HATEOAS.

Most developers aren't working in a domain and environment where the diversity of stakeholders is maximally broad for both the client(s) and server(s), so "going full HATEOAS" is often overkill, but you should still understand it, in the same way that you need to understand why data schemas ideally conform to fourth normal form, even if your production data is denormalized in practice.

While some benefits from some REST practices can start accruing even in the single developer situation, simply because there can be costs to coordinating between present-you and various versions of past-you and future-you, and their respective client and server deployments, that only makes a case for partial adoption. By all means, only use the practices and patterns that make sense and solve or avoid a pain point for you in your situation rather than being dogmatic.

In that sense, REST and HATEOAS shouldn't be considered in any different light than other aspects of writing software such as external dependencies, or changing the toolchain, or splitting some code into its own library or module, or publishing code as open source; sometimes it makes sense, sometimes not (especially when the costs are concrete and the benefits hypothetical).


If you're writing a web app that only works in a browser you control, then no, you won't benefit from hypermedia. The rest of us like search engines being able to index our sites though.


tools




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: