Hypa.Conn (Hypa v0.3.0)
View SourceUtilities to work with Plug.Conn structs that make it easier to use
htmx.
Response headers
This module provides functions to add all htmx response headers.
| Header | Function |
|---|---|
HX-Location | put_hx_location/2 |
HX-Push-Url | put_hx_push_url/2 |
HX-Redirect | put_hx_redirect/2 |
HX-Refresh | put_hx_refresh/2 |
HX-Replace-Url | put_hx_replace_url/2 |
HX-Reswap | put_hx_reswap/2 |
HX-Retarget | put_hx_retarget/2 |
HX-Reselect | put_hx_reselect/2 |
HX-Trigger | put_hx_trigger/2 |
HX-Trigger-After-Settle | put_hx_trigger_after_settle/2 |
HX-Trigger-After-Swap | put_hx_trigger_after_swap/2 |
Summary
Functions
Adds the HX-Location response header which allows you to do a client-side
redirect that does not do a full page reload.
Adds the HX-Push-Url response header which pushes a new URL into the history
stack.
Adds the HX-Redirect response header which can be used to do a client-side
redirect to a new location.
Adds the HX-Refresh response header which, when set to "true", will do a
client-side full refresh of the page.
Adds the HX-Replace-Url response header which will replace the current URL
in the location bar.
Adds the HX-Reselect response header which is a CSS selector that allows you
to choose which part of the response is used to be swapped in. It overrides an
existing hx-select on the
triggering element.
Adds the HX-Reswap response header which allows you to specify how the
response will be swapped.
Adds the HX-Retarget response header which is a CSS selector that updates
the target of the content update to a different element on the page.
Adds the HX-Trigger response header which allows you to trigger client-side
events.
Adds the HX-Trigger-After-Settle response header which allows you to trigger
client-side events after the settle step.
Adds the HX-Trigger-After-Swap response header which allows you to trigger
client-side events after the swap step.
Functions
Adds the HX-Location response header which allows you to do a client-side
redirect that does not do a full page reload.
See the htmx docs for more details.
Examples
iex> conn(:get, "/foo")
...> |> Hypa.Conn.put_hx_location("/bar")
...> |> get_resp_header("hx-location")
["/bar"]
Adds the HX-Push-Url response header which pushes a new URL into the history
stack.
See the htmx docs for more details.
Examples
iex> conn(:get, "/foo")
...> |> Hypa.Conn.put_hx_push_url("/bar")
...> |> get_resp_header("hx-push-url")
["/bar"]
Adds the HX-Redirect response header which can be used to do a client-side
redirect to a new location.
See the htmx docs for more details.
Examples
iex> conn(:get, "/foo")
...> |> Hypa.Conn.put_hx_redirect("/bar")
...> |> get_resp_header("hx-redirect")
["/bar"]
Adds the HX-Refresh response header which, when set to "true", will do a
client-side full refresh of the page.
Examples
iex> conn(:get, "/foo")
...> |> Hypa.Conn.put_hx_refresh(true)
...> |> get_resp_header("hx-refresh")
["true"]
Adds the HX-Replace-Url response header which will replace the current URL
in the location bar.
See the htmx docs for more details.
Examples
iex> conn(:get, "/foo")
...> |> Hypa.Conn.put_hx_replace_url("/bar")
...> |> get_resp_header("hx-replace-url")
["/bar"]
Adds the HX-Reselect response header which is a CSS selector that allows you
to choose which part of the response is used to be swapped in. It overrides an
existing hx-select on the
triggering element.
Examples
iex> conn(:get, "/foo")
...> |> Hypa.Conn.put_hx_reselect("#myelement")
...> |> get_resp_header("hx-reselect")
["#myelement"]
Adds the HX-Reswap response header which allows you to specify how the
response will be swapped.
See the htmx docs for more details.
Examples
iex> conn(:get, "/foo")
...> |> Hypa.Conn.put_hx_reswap("outerHTML")
...> |> get_resp_header("hx-reswap")
["outerHTML"]
Adds the HX-Retarget response header which is a CSS selector that updates
the target of the content update to a different element on the page.
Examples
iex> conn(:get, "/foo")
...> |> Hypa.Conn.put_hx_retarget("#myelement")
...> |> get_resp_header("hx-retarget")
["#myelement"]
Adds the HX-Trigger response header which allows you to trigger client-side
events.
See the htmx docs for more details.
Examples
iex> conn(:get, "/foo")
...> |> Hypa.Conn.put_hx_trigger("firstevent, secondevent")
...> |> get_resp_header("hx-trigger")
["firstevent, secondevent"]
Adds the HX-Trigger-After-Settle response header which allows you to trigger
client-side events after the settle step.
See the htmx docs for more details.
Examples
iex> conn(:get, "/foo")
...> |> Hypa.Conn.put_hx_trigger_after_settle("firstevent, secondevent")
...> |> get_resp_header("hx-trigger-after-settle")
["firstevent, secondevent"]
Adds the HX-Trigger-After-Swap response header which allows you to trigger
client-side events after the swap step.
See the htmx docs for more details.
Examples
iex> conn(:get, "/foo")
...> |> Hypa.Conn.put_hx_trigger_after_swap("firstevent, secondevent")
...> |> get_resp_header("hx-trigger-after-swap")
["firstevent, secondevent"]