3 releases
0.5.0-rc | Mar 20, 2020 |
---|---|
0.5.0-beta | Mar 4, 2020 |
0.5.0-alpha | Mar 3, 2020 |
#1364 in HTTP server
Used in roa-websocket
105KB
2K
SLoC
Roa-router
The router module of roa.
This module provides an endpoint RouteEndpoint
and a context extension RouterParam
.
Example
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(())
}
Dependencies
~13MB
~216K SLoC