Fix fullstack axum integration docs (#3263)

* Fix broken fullstack doc tests

* include all features in doc test

* fix clippy
This commit is contained in:
Evan Almloff authored and GitHub committed 2024-12-02 11:35:13 -08:00
1 parent 354c4ce9cc
commit 9dc567255a
8 files changed
+51 -116

No files matched your search

+11 -3
View File
@@ -3,13 +3,16 @@ This method interacts with information from the current request. The request may
1. The initial SSR render if this method called from a [`Component`](dioxus_lib::prelude::component) or a [`server`](crate::prelude::server) function that is called during the initial render
```rust
# use dioxus::prelude::*;
#[component]
fn PrintHtmlRequestInfo() -> Element {
// The server context only exists on the server, so we need to put it behind a server_only! config
server_only! {
// Since we are calling this from a component, the server context that is returned will be from
// the html request for ssr rendering
println!("headers are {:?}", server_context().request_parts().headers);
let context = server_context();
let request_parts = context.request_parts();
println!("headers are {:?}", request_parts.headers);
}
rsx! {}
}
@@ -18,11 +21,14 @@ fn PrintHtmlRequestInfo() -> Element {
2. A request to a [`server`](crate::prelude::server) function called directly from the client (either on desktop/mobile or on the web frontend after the initial render)
```rust
# use dioxus::prelude::*;
#[server]
async fn read_headers() -> Result<(), ServerFnError> {
// Since we are calling this from a server function, the server context that is may be from the
// initial request or a request from the client
println!("headers are {:?}", server_context().request_parts().headers);
let context = server_context();
let request_parts = context.request_parts();
println!("headers are {:?}", request_parts.headers);
Ok(())
}
@@ -32,7 +38,9 @@ fn CallServerFunction() -> Element {
button {
// If you click the button, the server function will be called and the server context will be
// from the client request
onclick: move |_| read_headers().await,
onclick: move |_| async {
_ = read_headers().await
},
"Call server function"
}
}