Live data from Hacker News

Hotwire: HTML over the Wire

hotwire.dev

571–573 of 573 posts

Re: Hotwire: HTML over the Wire

#571

Earlier quoted context omitted.

> RESTful APIs serving up JSON works for all 3, as does GraphQL (not a fan, but many are). This however is totally web-specific HTML is a machine-readable format, like XML and JSON. Have your back end represent a given resource as microformatted-semantic markup, send it gzipped over the wire, and you've got the data exchange you need, even if your mobile app isn't already dressed-up webview.

Are you still referring to dedicated API routes, or are you talking about annotating your UI to the point where it can serve as the API as well? I remember the latter being the vision behind things like RDFa, but those approaches never took off, for a variety of reasons.

> annotating your UI to the point where it can serve as the API as well

At that point you might as well serve XML and use an XSLT transform (+ CSS) to render the view on the client (yes, this is still possible without JavaScript).

Re: Hotwire: HTML over the Wire

#572
post #539
post #537

Earlier quoted context omitted.

> But with LV wouldn't you need to create both a LV and a regular controller? That's a huge amount of code duplication. You just do LiveView instead of a regular controller. No duplication. When you request a page, it is render on the server and all of the HTML is returned over HTTP as usual. After the client has received the HTML updates, live updates can go over a websocket. For instance you start typing in a searc…

> You just do LiveView instead of a regular controller. No duplication. Yes but this is only in the happy case when the client is fully enhanced no? What happens if you hook up a phx click event to increment a like counter. After the page is loaded, if you click the + to increment it while having JavaScript disabled it's not going to do anything right? But with Hotwire Turbo, if you have a degraded client with no JS,…

Yes, the `phx-click` doesn't automatically get translated to a link or form submission. You can still design the page to work without javascript. For instance by having a "+" button be a normal form or link and then have phx-click intercept it when javascript is enabled. This can be done with one LiveView module without having to also have a separate regular controller.

One way to do it would be to in the `mount` function handle normal non-javascript params being sent and a `handle_event` function handle `phx-click`.

I don't know if there is already a way to have `phx-click` with fallback to HTTP in a less "manual" way. It should be possible to make.

Re: Hotwire: HTML over the Wire

#573
post #74

Spoiler, it's just Ajax but it pushes the data through your templates before sending it to the client. We were doing this literally over a decade ago in the early days of XHR.

Isn't the point that it's a framework to accomplish this, rather than "look what we can do!"?
Post reply on HN