I keep seeing the argument that REST got reduced to JSON over HTTP, and that HTMX and server-rendered HTML are closer to the original idea. What is the distinction, and does it actually matter when building an app?
Is server-rendered HTML really closer to REST than a JSON API?
Answers
The missing piece in a lot of the discussion is hypermedia. In REST, a response can give the client links or other controls for the actions currently available, rather than requiring the client to have every workflow hard-coded in advance.
HTML has links and forms built in, so server-rendered pages are a natural way to express that. HTMX can extend the same idea to updates of part of a page. That does not make every HTML application automatically RESTful, though.
Reply to this answer
People also use REST more loosely to mean an HTTP API with resource-oriented paths and methods. That convention can still make an API easier to understand, even if it does not satisfy the full architectural definition.
If you need to be precise, describe the actual design instead of relying on the label. Does the client discover available actions from responses, or does it already know the endpoints and workflow?
Reply to this answer
For the app itself, I'd start with the interaction requirements rather than the terminology. Server-rendered HTML can keep a lot of UI logic on the server, while a single-page app may be a better fit when the client needs more complex, independent state and interactions.
HTMX offers a middle ground for updating parts of a server-rendered page without necessarily building a separate client application.
Reply to this answer
Calling something a REST API tells you surprisingly little on its own. Some HTTP APIs are closer to remote procedure calls, where endpoints represent operations rather than resources. That is a different design choice from whether responses happen to be JSON or HTML.
Reply to this answer
Add your answer
Answers are reviewed before publication.
_p62+velourrivet.7:
JSON can carry links and action information too. The format alone does not decide whether an API uses hypermedia.