liveBook · Manning

Hx-get attribute

As explained in Quarkus in Action

The hx-get attribute configures HTMX to submit an HTTP GET request to a specified endpoint.

Use `hx-get` to make an HTML element request an endpoint with HTTP GET. On a form, submitting sends its input values as parameters. Pair it with `hx-target` to put the returned HTML in another element instead of replacing the form. section 6.2.3

A reservation page uses `hx-get="/available"` on a date-selection form. Its availability container also uses `hx-get="/available"`: `hx-trigger` requests the table on page load or a reservation-update event, while `hx-include` supplies the selected dates. The endpoint returns a rendered Qute table. section 6.2.3

Listing 6.13 Including the list of available cars in the index page
<h2>Available cars to rent</h2>
<form hx-get="/available" hx-target="#availability">
  <p>Start date:<input id="startDateInput" type="date"
                       name="startDate" value="{startDate}"/></p>
  <p>End date:<input id="endDateInput" type="date"
                     name="endDate" value="{endDate}"/></p>
  <input type="submit" value="Update list"/>
</form>
<div id="availability" hx-get="/available"  #1
     hx-trigger="load, update-available-cars-list from:body"
     hx-include="[id='startDateInput'],[id='endDateInput']">
  <!-- To be replaced by the result of calling /available -->
</div>

The form and availability container call the same endpoint for different triggers; the form targets the container for replacement. section 6.2.3

How Quarkus in Action covers it

How deep it goes
Shows form and load-triggered GET requests, included parameters, and response targeting; stops short of HTMX internals.
Examples
Uses date inputs to request available cars and a container that refreshes on load or after a reservation.
What it assumes
Assumes basic HTML form and REST endpoint knowledge while showing the required HTMX attributes.
What you can do after
Apply it via HTMX to request rendered HTML and update a chosen page element.
How it connects
Connects HTML forms, REST endpoints, Qute templates, `hx-target`, `hx-trigger`, and `hx-include`.

Also explained in

Compare how 2 books explain hx-get attribute →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Quarkus in Action. The section links point to the parts of the book it draws on.