Crates.io | roa-router |
lib.rs | roa-router |
version | 0.5.0-rc |
source | src |
created_at | 2020-03-03 14:52:09.101679 |
updated_at | 2020-03-20 13:47:44.919984 |
description | router implementation for roa |
homepage | https://github.com/Hexilee/roa/wiki |
repository | https://github.com/Hexilee/roa |
max_upload_size | |
id | 214934 |
size | 33,139 |
The router module of roa.
This module provides an endpoint RouteEndpoint
and a context extension RouterParam
.
use roa_router::{Router, RouterParam};
use roa_core::App;
use roa_core::http::StatusCode;
use roa_tcp::Listener;
use async_std::task::spawn;
#[tokio::test]
async fn gate() -> Result<(), Box<dyn std::error::Error>> {
let mut router = Router::<()>::new();
router
.gate_fn(|_ctx, next| next)
.get("/", |_ctx| async move {
Ok(())
});
let (addr, server) = App::new(()).gate(router.routes("/route")?).run()?;
spawn(server);
let resp = reqwest::get(&format!("http://{}/route", addr)).await?;
assert_eq!(StatusCode::OK, resp.status());
let resp = reqwest::get(&format!("http://{}/endpoint", addr)).await?;
assert_eq!(StatusCode::NOT_FOUND, resp.status());
Ok(())
}