Towards the end you can put it all together and trim it down, not sure if there's tooling that auto joins some of the CSS as necessary though.
can use one of three attributes named <template-engine>-temlpate (e.g. mustache-template)a lot of folks conflate AJAX w/ JSON apis, and can't easily imagine an endpoint returning partial bits of HTML that have nothing to do with a public JSON API
worse, people have been misled to believe that JSON APIs are REST-ful
we have a lot of work to do
That matches by experience and is kind of ironic, considering that the X in "AJAX" once stood for XML. ;)
What other client-side UI frameworks do you recommend? I'm liking what I'm seeing with HTMX due to its small size and simplicity.
https://htmx.org/attributes/hx-swap-oob/
you can also select content by a selector:
https://htmx.org/attributes/hx-select/
and there is infrastructure for general response transformations via the extensions mechanism:
https://htmx.org/extensions/client-side-templates/
See the source code here:
https://unpkg.com/[email protected]/dist/ext/client-side-templa...
I've never actually used a backend that couldn't return arbitrary content types. Those exist?
Any serious framework would be able to handle this without any hiccups.
To migrate to our flashy new Angular V1 application, we added a application/json content-type that instead of returning the template, returned the data that the template used. So we could endpoint-by-endpoint migrate to the SPA we were building.
Was simply a matter of making the data required for the views a bit more advertised internally, so the controllers could instead not render the views when the content-type is json.
It wouldn't be the prettiest HTML but you could work with it via CSS and JS.
For sure. Most of the backends we write only return JSON. If you request HTML or any other content-type, we return nothing. We just don't implement it.
If you write your backend from scratch and only intend for it to be used only with your web front-end, you can make it return bits of HTML (I have several applications in jQuery that work like this -- the value of the response just gets inserted via ("#id").html(val)).
Our current backends are written to support multiple generic consumers of which a web front-end is only one.
Much easier to use client-side templating as suggested by the author.
https://htmx.org/examples/
There is a slight deal-breaker for me. Much of the functionality revolves around hx-swap'ing i.e. writing the contents of a response as HTML into/around tags. This requires the server-side to return HTML instead of JSON. From the docs:
"Note that when you are using htmx, on the server side you respond with HTML, not JSON. This keeps you firmly within the original web programming model, using Hypertext As The Engine Of Application State without even needing to really understand that concept."
I would love to use this with existing REST backends, but most are only able to return JSON. How does one use this for AJAX without rewriting existing backends?