mirror of
https://github.com/robertwayne/axum-htmx
synced 2024-11-29 22:54:32 +01:00
Update README.md
This commit is contained in:
parent
f406f74591
commit
ed1820d7fc
1 changed files with 30 additions and 0 deletions
30
README.md
30
README.md
|
@ -118,6 +118,9 @@ async fn get_index(HxBoosted(boosted): HxBoosted) -> impl IntoResponse {
|
||||||
|
|
||||||
### Example: Responders
|
### 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
|
```rust
|
||||||
use axum_htmx::HxResponseTrigger;
|
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
|
### Example: Router Guard
|
||||||
|
|
||||||
```rust
|
```rust
|
||||||
|
|
Loading…
Reference in a new issue