Skip to content

Instantly share code, notes, and snippets.

@masakielastic
Last active August 18, 2025 21:38
Show Gist options
  • Select an option

  • Save masakielastic/5930ae8026cc0753234ebebb74ac884d to your computer and use it in GitHub Desktop.

Select an option

Save masakielastic/5930ae8026cc0753234ebebb74ac884d to your computer and use it in GitHub Desktop.
warp で HTTP サーバー

warp で HTTP サーバー

実行

Cargo.tomlsrc/main.rs を設置して cargo run を実行します。

TLS

v0.4.0, v0.4.1 では TLS が無効になっているので v0.3 系を利用します。issue の記録によると TLS が無効になっているのは hyper のバージョンを v0.1.4 から v1 系に引き上げたことや warp の API を変更するためだそうです。

[package]
name = "hello-warp"
version = "0.1.0"
edition = "2024"
[dependencies]
tokio = { version = "1", features = ["full"] }
warp = { version = "0.4", features = ["server"] }
#![deny(warnings)]
use warp::Filter;
#[tokio::main]
async fn main() {
let base = warp::path::end().map(|| "Hello, World at root!");
let route =
warp::path!(String).map(|name| format!("{}", name));
let routes = warp::get().and(
base
.or(route)
);
warp::serve(routes).run(([127, 0, 0, 1], 3030)).await;
}
[package]
name = "hello-warp"
version = "0.1.0"
edition = "2021"
[dependencies]
tokio = { version = "1", features = ["full"] }
warp = { version = "0.3", features = ["default", "tls"]}
#![deny(warnings)]
#[tokio::main]
async fn main() {
use warp::Filter;
let routes = warp::any().map(|| "Hello, World!");
warp::serve(routes)
.tls()
.cert_path("localhost.pem")
.key_path("localhost-key.pem")
.run(([127, 0, 0, 1], 3030))
.await;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment