roa-router

Crates.ioroa-router
lib.rsroa-router
version0.5.0-rc
sourcesrc
created_at2020-03-03 14:52:09.101679
updated_at2020-03-20 13:47:44.919984
descriptionrouter implementation for roa
homepagehttps://github.com/Hexilee/roa/wiki
repositoryhttps://github.com/Hexilee/roa
max_upload_size
id214934
size33,139
xixi (Hexilee)

documentation

https://docs.rs/roa-router

README

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(())
}
Commit count: 722

cargo fmt