Both of the following "hello world" samples build successfully, but only the first results in a page that says "Hello World"; the second one gives me an error about the page not being found. The Cargo.toml file is the same for both. I'm accessing the IP 127.0.0.1:3030
.
I tried accessing the second one using curl, but it returned nothing and went back to the prompt. The browser I used for the successful first one is Microsoft Edge 84.
Why doesn't the second one work?
First one
#![deny(warnings)]
use warp::Filter;
#[tokio::main]
async fn main() {
// Match any request and return hello world!
let routes = warp::any().map(|| "Hello, World!");
warp::serve(routes).run(([127, 0, 0, 1], 3030)).await;
Second one
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;
}
Cargo.toml
[package]
name = "warptest"
version = "0.1.0"
authors = ["user"]
edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
tokio = { version = "0.2", features = ["full"] }
warp = "0.2"