3 releases
0.7.0-alpha.2 | Jul 2, 2025 |
---|---|
0.7.0-alpha.1 | May 31, 2025 |
0.7.0-alpha.0 | May 14, 2025 |
#1089 in HTTP server
852 downloads per month
490KB
7.5K
SLoC
Dioxus utilities for the Axum server framework.
Example
#![allow(non_snake_case)]
use dioxus::prelude::*;
fn main() {
#[cfg(feature = "web")]
// Hydrate the application on the client
dioxus::launch(app);
#[cfg(feature = "server")]
{
tokio::runtime::Runtime::new()
.unwrap()
.block_on(async move {
// Get the address the server should run on. If the CLI is running, the CLI proxies fullstack into the main address
// and we use the generated address the CLI gives us
let address = dioxus::cli_config::fullstack_address_or_localhost();
let listener = tokio::net::TcpListener::bind(address)
.await
.unwrap();
axum::serve(
listener,
axum::Router::new()
// Server side render the application, serve static assets, and register server functions
.serve_dioxus_application(ServeConfigBuilder::default(), app)
.into_make_service(),
)
.await
.unwrap();
});
}
}
fn app() -> Element {
let mut text = use_signal(|| "Click the button to run a server function".to_string());
rsx! {
button {
onclick: move |_| async move {
if let Ok(data) = get_server_data().await {
text.set(data);
}
},
"Run a server function"
}
"Server said: {text}"
}
}
#[server(GetServerData)]
async fn get_server_data() -> ServerFnResult<String> {
Ok("Hello from the server!".to_string())
}
Dependencies
~19–48MB
~1M SLoC