3 ms·
Because it's just not that great. If you have a client that's going to make a request to your server, why not just expose the necessary data at a json route an
by hombre_fatal 2y ago
Because it's just not that great.
If you have a client that's going to make a request to your server, why not just expose the necessary data at a json route and let the client do what it wishes with that data? It's already the simple, general solution.
With Htmlx, you expose an html route that must be synchronized with the html already sent over the wire so that it can be inlined into the existing html. This means that if the surrounding html/classes change, you may have to update a bunch of fragments because they depend on the existing html. Even if the data itself never changes.
Sending just the data is simpler and more versatile.
- em-bee 2y agoexactly, this is why i prefer using frontend frameworks. the backend now doesn't need any more complex UI logic, and becomes much more reusable. i have been reusing the same backend code without changes for all websites that i built in the last 10 years. even for a single website i can create multiple frontends (like a mobile client for example) without having to change the backend, because all frontends can use the same json api.
- what2 2y agoAs with everything in engineering the definitive answer is "it depends". If your JSON API is guided by your UI then you are gonna have a fun time keeping with the changes (been there, done that). Sure you know that to add a new field on your page you will need to add it on the API's JSON, then on the JS client code, then on your client template... Compare this to adding it on the HTML generated on the server and... done! There is value in differentiating between Data API and Hypermedia (UI) API, you can read more about it here https://htmx.org/essays/hypermedia-apis-vs-data-apis/ https://htmx.org/essays/hypermedia-apis-vs-data-apis/ And note that is not an universal truth applicable on all cases because "it depends"
- em-bee 2y agowhen i add something to the server generated html, first of all i have to change the html template, then i have to add the field to the function/class that feeds the data into the template, and i have to add it to the database if it is not already there. with a frontend framework i add it to the html template in the frontend, and i add it to the function/class that generates the json output. and again to the database if not already there. as far as i can tell, that's the same amount of code that needs to be changed. yes, there is one piece of extra code to generate json, but that is either a standard library or something you write once. either way, the json generator should not need to be changed.