diff --git a/README.md b/README.md index 7754a66..20e0b3e 100644 --- a/README.md +++ b/README.md @@ -118,6 +118,9 @@ async fn get_index(HxBoosted(boosted): HxBoosted) -> impl IntoResponse { ### Example: Responders +We can trigger any event being listened to by the DOM using an [htmx +trigger](https://htmx.org/attributes/hx-trigger/) header. + ```rust use axum_htmx::HxResponseTrigger; @@ -130,6 +133,33 @@ async fn index() -> (&'static str, HxResponseTrigger) { } ``` +...`htmx` even allow arbitrary data to be sent along with the event, which we +can use via the `serde` feature flag and the `HxEvent` type. + +```rust +use axum_htmx::HxEvent; + +// Note that we are using `HxResponseTrigger` from the `axum_htmx::serde` module +// instead of the root module. +use axum_htmx::serde::HxResponseTrigger; + +async fn index() -> (&'static str, HxResponseTrigger) { + let event = HxEvent::new_with_data( + "my-event", + json!({"level": "info", "message": { + "title": "Hello, world!", + "body": "This is a test message.", + }}), + ) + .unwrap(); + + ("Hello, world!", HxResponseTrigger(event)) +} +``` + +```rust +``` + ### Example: Router Guard ```rust