Added hx_boosted_by docs into README

This commit is contained in:
Dan Alekseev 2024-04-06 11:39:00 +04:00
parent 7ef8f4485c
commit 6be4fcfb23

View file

@ -24,6 +24,7 @@
- [Extractors](#extractors)
- [Responders](#responders)
- [Request Guards](#request-guards)
- [Macroses](#macroses)
- [Examples](#examples)
- [Example: Extractors](#example-extractors)
- [Example: Responders](#example-responders)
@ -89,6 +90,12 @@ trivially set the `HX-Request` header themselves. This is merely a convenience
for preventing users from receiving partial responses without context. If you
need to secure an endpoint you should be using a proper auth system._
## Macroses
__Requires features `macros`.__
In addition to the HxBoosted extractor, the library provides macroses `hx_boosted_by` and it's async version `hx_boosted_by_async` for managing the response based on the presence of the `HX-Boosted` header.
## Examples
### Example: Extractors
@ -185,6 +192,26 @@ fn router_two() -> Router {
}
```
### Example: Macros
```rust
use axum_htmx::hx_boosted_by;
#[hx_boosted_by(with_layout)]
async fn get_hello(Path(name): Path<String>) -> Html<String> {
Html(format!("Hello, {}!", name)
}
#[hx_boosted_by(with_layout)]
async fn get_bye(Path(name): Path<String>) -> Html<String> {
Html(format!("Bye, {}!", name)
}
fn with_layout(Html(partial): Html<String>) -> Html<String> {
Html(format!("<html><body>{}</body></html>", partial))
}
```
## Feature Flags
<!-- markdownlint-disable -->