| ▲ | ranger_danger 7 hours ago | |
Does it automatically parse JSON responses from servers into objects? This is my one big gripe about htmx, even though the devs and other users keep telling me I shouldn't want that as a feature and that it "doesn't make sense". Sorry if I need to use existing APIs I cannot change. | ||
| ▲ | amaury_bouchard 7 minutes ago | parent | next [-] | |
µJS is HTML-over-the-wire, so it doesn't parse JSON responses natively (same limitation as HTMX). That said, you can work around it using the `mu:before-render` event, which lets you intercept the raw response before it hits the DOM and handle it however you want. It's not as clean as native JSON support, I'll admit. If your use case is primarily consuming existing JSON APIs, µJS (and HTMX) are probably not the right fit, they're designed around server-rendered HTML fragments. | ||
| ▲ | williamcotton 3 hours ago | parent | prev | next [-] | |
| ||
| ▲ | scuff3d an hour ago | parent | prev | next [-] | |
They're right through, the entire point of HTMX is to use "HTML as the Engine of Application State". Shipping JSON to the front end to be rednered is antithetical to that. As someone else mentioned, having your own server backend act as an intermediary between your front end and the API that serves JSON is probably the most straightforward solution to keep everything HTMX-y. | ||
| ▲ | WesolyKubeczek 6 hours ago | parent | prev [-] | |
I came to a conclusion that when you have an SPA with JSON-spitting backend where you cannot make the backend spit out chunks of HTML, htmx and similar libraries/frameworks are not suitable. They are suitable if you already have a multi-page application like we used to in 2006, or if you design it from the ground up. | ||