Skip to content

Commit

Permalink
Merge pull request #616 from hermit-os/axum
Browse files Browse the repository at this point in the history
feat: add axum example
  • Loading branch information
mkroening authored Sep 17, 2024
2 parents 05f1312 + 9462269 commit 5ab21e2
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:9975").await?;
axum::serve(listener, app).await?;

Ok(())
}

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

0 comments on commit 5ab21e2

Please sign in to comment.