]> piware.de Git - learn-rust.git/commitdiff
warp-server: Initial hello world
authorMartin Pitt <martin@piware.de>
Tue, 1 Nov 2022 15:15:39 +0000 (16:15 +0100)
committerMartin Pitt <martin@piware.de>
Tue, 1 Nov 2022 15:15:39 +0000 (16:15 +0100)
warp-server/Cargo.toml [new file with mode: 0644]
warp-server/src/main.rs [new file with mode: 0644]

diff --git a/warp-server/Cargo.toml b/warp-server/Cargo.toml
new file mode 100644 (file)
index 0000000..ffbe552
--- /dev/null
@@ -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 (file)
index 0000000..70b3cc3
--- /dev/null
@@ -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;
+}