3 ms·
How do you organize a backend for a htmx based frontend? Specifically getting templates that serve as reusable components, but also endpoints (there is some pro
by spion 3y ago
How do you organize a backend for a htmx based frontend? Specifically getting templates that serve as reusable components, but also endpoints (there is some proliferation of endpoints which I remember from my days with ASP.NET MVC partials.
- recursivedoubts 3y agodepends a lot on what your backend gives you i agree it can spiral out of control if you try to do too much, e.g. a routes file that is just incomprehensible i often end up reusing the same controller method to handle a few related routes, using pattern matching in the route declaration i think also picking your battles and not getting too fiddly with screens that don't matter so much also helps a lot here
- traverseda 3y agoSo you start by just re-sending the entire page but with content changed. Generally you'd use query parameters, like say you have a page with a table and you need to sort it. Add to your query parameters what order you want them in, re-render the whole page. Then once you've got it figured out you just return the part of the template that you actually need to. Makes sense when you think of it as a progressive enhancement on a plain html page.