Update README.md

This commit is contained in:
Rob Wagner 2023-10-23 23:25:18 -04:00
parent f406f74591
commit ed1820d7fc
No known key found for this signature in database
GPG key ID: 53CCB4497B15CF61

View file

@ -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