Hacker News new | ask | show | jobs
by appplication 970 days ago
I feel like I want to like htmx, and the concepts sound cool. But json is such a nice generic serialization format. Like my API can be in service of my frontend, but also other applications. While, unless I misunderstand it, htmx seems to philosophically believe the backend is the frontend.

Are there any patterns where you have an API with nice json payloads but also use htmx to push the rendering to backend? What do you do when you have users that just want basic data from the API? Do you add json endpoints, or is it more of a “fuck you learn how to accept html” situation?

1 comments

You can have both a hypermedia API and a data (JSON) API. Your hypermedia API is a lot more lightweight and flexible as it's tied to your web app. The HTMX authors talk about that topic in their book: https://hypermedia.systems/json-data-apis/

"These two different types of APIs have different strengths and needs, so it makes sense to use both. The hypermedia approach can be used for your web application, allowing you to specialize the API for the “shape” of your application. The Data API approach can be used for other, non-hypermedia clients like mobile, integration partners, etc.

Note that by splitting these two APIs apart, you reduce the pressure to constantly change a general Data API to address application needs. Your Data API can focus on remaining stable and reliable, rather than requiring a new version with every added feature."