roa-router 0.5.0-rc

router implementation for roa
roa-router-0.5.0-rc doesn't have any documentation.

Stable Test codecov Rust Docs Crate version Download Version License: MIT

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(())
}