gomponents-htmxmaragu.dev/gomponents-htmx/http Index | Examples | Files

package http

import "maragu.dev/gomponents-htmx/http"

Package http provides helpers for working with HTMX HTTP requests. See https://htmx.org/reference/#headers

Index

Examples

Functions

func GetCurrentURL

func GetCurrentURL(headers http.Header) string

GetCurrentURL of the browser.

func GetPrompt

func GetPrompt(headers http.Header) string

GetPrompt from the user response to an hx-prompt. See https://htmx.org/attributes/hx-prompt

func GetTarget

func GetTarget(headers http.Header) string

GetTarget returns the id of the target element if it exists.

func GetTrigger

func GetTrigger(headers http.Header) string

GetTrigger returns the id of the triggered element if it exists.

func GetTriggerName

func GetTriggerName(headers http.Header) string

GetTriggerName returns the name of the triggered element if it exists.

func IsBoosted

func IsBoosted(headers http.Header) bool

IsBoosted indicates that the request is via an element using hx-boost.

Example

Code:play 

package main

import (
	"net/http"

	hxhttp "maragu.dev/gomponents-htmx/http"
)

func main() {
	_ = http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		if hxhttp.IsBoosted(r.Header) {
			// Boosted!
		}
	})
}

func IsHistoryRestoreRequest

func IsHistoryRestoreRequest(headers http.Header) bool

IsHistoryRestoreRequest returns whether the request is for history restoration after a miss in the local history cache.

func IsRequest

func IsRequest(headers http.Header) bool

IsRequest returns whether this is a HTMX request.

func SetLocation

func SetLocation(headers http.Header, v string)

SetLocation allows you to do a client-side redirect that does not do a full page reload. See https://htmx.org/headers/hx-location

func SetPushURL

func SetPushURL(headers http.Header, v string)

SetPushURL pushes a new URL into the history stack. See https://htmx.org/headers/hx-push-url

func SetRedirect

func SetRedirect(headers http.Header, v string)

SetRedirect can be used to do a client-side redirect to a new location.

func SetRefresh

func SetRefresh(headers http.Header)

SetRefresh will make the client side do a a full refresh of the page.

Example

Code:play 

package main

import (
	"net/http"

	hxhttp "maragu.dev/gomponents-htmx/http"
)

func main() {
	_ = http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		hxhttp.SetRefresh(w.Header())
	})
}

func SetReplaceURL

func SetReplaceURL(headers http.Header, v string)

SetReplaceURL replaces the current URL in the location bar. See https://htmx.org/headers/hx-replace-url

func SetReswap

func SetReswap(headers http.Header, v string)

SetReswap allows you to specify how the response will be swapped. See https://htmx.org/attributes/hx-swap

func SetRetarget

func SetRetarget(headers http.Header, v string)

SetRetarget sets a CSS selector that updates the target of the content update to a different element on the page.

func SetTrigger

func SetTrigger(headers http.Header, v string)

SetTrigger allows you to trigger client side events. See https://htmx.org/headers/hx-trigger

func SetTriggerAfterSettle

func SetTriggerAfterSettle(headers http.Header, v string)

SetTriggerAfterSettle allows you to trigger client side events. See https://htmx.org/headers/hx-trigger

func SetTriggerAfterSwap

func SetTriggerAfterSwap(headers http.Header, v string)

SetTriggerAfterSwap allows you to trigger client side events. See https://htmx.org/headers/hx-trigger

Source Files

http.go

Version
v0.6.1 (latest)
Published
Oct 11, 2024
Platform
linux/amd64
Imports
1 packages
Last checked
1 month ago

Tools for package owners.