Skip to content

Commit

Permalink
feat: add axum example
Browse files Browse the repository at this point in the history
Signed-off-by: Martin Kröning <[email protected]>
  • Loading branch information
mkroening committed Sep 13, 2024
1 parent fa8ede7 commit 297a831
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ members = [
"benches/alloc",
"benches/micro",
"benches/netbench",
"examples/axum",
"examples/demo",
"examples/fuse_test",
"examples/hello_world",
Expand Down
10 changes: 10 additions & 0 deletions examples/axum/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[package]
name = "axum-example"
edition = "2021"

[dependencies]
axum = "0.7"
tokio = "1"

[target.'cfg(target_os = "hermit")'.dependencies]
hermit = { path = "../../hermit" }
19 changes: 19 additions & 0 deletions examples/axum/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
use axum::routing::get;
use axum::Router;
#[cfg(target_os = "hermit")]
use hermit as _;
use tokio::{io, net};

#[tokio::main(flavor = "current_thread")]
async fn main() -> io::Result<()> {
let app = Router::new().route("/", get(root));

let listener = net::TcpListener::bind("0.0.0.0:3000").await?;
axum::serve(listener, app).await?;

Ok(())
}

async fn root() -> &'static str {
"Hello, World!"
}

0 comments on commit 297a831

Please sign in to comment.