From: Martin Pitt Date: Tue, 1 Nov 2022 15:15:39 +0000 (+0100) Subject: warp-server: Initial hello world X-Git-Url: https://piware.de/gitweb/?a=commitdiff_plain;h=660eb0d2c9664a89a379f0d65923a4c8721a20b8;p=learn-rust.git warp-server: Initial hello world --- diff --git a/warp-server/Cargo.toml b/warp-server/Cargo.toml new file mode 100644 index 0000000..ffbe552 --- /dev/null +++ b/warp-server/Cargo.toml @@ -0,0 +1,10 @@ +[package] +name = "warp-server" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +tokio = { version = "1", features = ["full"] } +warp = "0.3" diff --git a/warp-server/src/main.rs b/warp-server/src/main.rs new file mode 100644 index 0000000..70b3cc3 --- /dev/null +++ b/warp-server/src/main.rs @@ -0,0 +1,12 @@ +use warp::Filter; + +#[tokio::main] +async fn main() { + // GET /hello/warp => 200 OK with body "Hello, warp!" + let hello = warp::path!("hello" / String) + .map(|name| format!("Hello, {}!", name)); + + warp::serve(hello) + .run(([127, 0, 0, 1], 3030)) + .await; +}