htmx4query

package
v0.2.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 4, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

README

htmx 4: QUERY and morph swaps

htmx 4 adds the QUERY method — safe and idempotent like GET, with the parameters in the body like POST — as hx-query, and ghtmx binds it like the other five verbs: hx-query={ Search } resolves against the QUERY /search registration at build time. This example pins 4.0.0 in its own ghtmx.json and pairs the new verb with the new swap style:

  • the search box issues a QUERY on every change (debounced) and on the search event that clears the field;
  • the handler reads the body itself — net/http parses form bodies only for POST, PUT, and PATCH;
  • the result list is swapped with hx-swap="innerMorph", so entries with stable ids keep their DOM nodes across responses — only rows that actually appear run the CSS appear animation, where an innerHTML swap would flash every row on every keystroke;
  • the page's htmx-config adds open to morphIgnore, so the <details> a visitor expanded stay open: a morph syncs attributes from the response, and the server never sends open.
ghtmx generate && go run ./cmd    # serves http://127.0.0.1:8088/search

Under a 2.0.10 pin both hx-query and innerMorph are reported as introduced in 4.0.0 (GHTMX-E0501), and ghtmx routes lists the QUERY registration beside the others.

Documentation

Overview

The htmx4-query example: htmx 4 adds the QUERY method — safe and idempotent like GET, with the parameters in the body like POST — and morph swaps that update a region in place instead of replacing it. A search box issues QUERY requests as you type (hx-query, the sixth route-bindable verb) and morphs the result list: entries present in both responses keep their DOM nodes (only newcomers run the appear animation), and with "open" in htmx.config.morphIgnore the <details> a visitor expanded stay expanded while the list around them changes. The compiler binds hx-query against the "QUERY /search" registration and validates innerMorph against the 4.0.0 pin in ghtmx.json.

Run it with:

ghtmx generate && go run ./cmd

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Routes

func Routes() *http.ServeMux

Routes builds the example's router; the official docs site mounts it as a live demo.

func Search(w http.ResponseWriter, r *http.Request)

Search answers a QUERY request. Its parameters travel in the body, form-encoded like a POST, but net/http parses bodies only for POST, PUT, and PATCH — so the handler reads and parses the body itself.

Types

type Package

type Package struct {
	Path string
	Doc  string
}

Package is one searchable entry: a Go standard-library package.

Directories

Path Synopsis
Command htmx4query serves the htmx4-query example standalone.
Command htmx4query serves the htmx4-query example standalone.
Package ghtmxgen is the central generated package: route path constants and typed route constructors, regenerated by ghtmx generate from the application's own route registrations.
Package ghtmxgen is the central generated package: route path constants and typed route constructors, regenerated by ghtmx generate from the application's own route registrations.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL