Created
March 5, 2021 15:13
-
-
Save fteychene/35a1ee3777159b86d246e0da011142c9 to your computer and use it in GitHub Desktop.
Warp route test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use warp::{Filter, Rejection}; | |
use warp::generic::Either; | |
fn other_routes() -> impl Filter<Error = Rejection, Extract = (Either<(Either<(String,), (String,)>,), (String,)>,)> + Clone + Send + Sync + 'static { | |
// GET /hi | |
let hi = warp::get().and(warp::path("hi").map(|| "Hello, World!".to_string())); | |
// GET /hello/from/warp | |
let hello_from_warp = warp::get().and(warp::path!("hello" / "from" / "warp").map(|| "Hello from warp!".to_string())); | |
// GET /sum/:u32/:u32 | |
let sum = warp::get().and(warp::path!("sum" / u32 / u32).map(|a, b| format!("{} + {} = {}", a, b, a + b))); | |
hi.or(hello_from_warp).or(sum) | |
} | |
#[tokio::main] | |
async fn main() { | |
// GET / | |
let hello_world = warp::path::end().map(|| "Hello, World at root!"); | |
let routes = warp::get().and(hello_world) | |
.or(other_routes()); | |
warp::serve(routes).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