Routerify-NG (Next Generation) is a modern, lightweight, idiomatic, and modular router for the Rust HTTP library Hyper 1.x.
It is a maintained and upgraded fork of the original Routerify, updated to work with the new Hyper service model and current versions of Hyper.
Project Status
Routerify-NG is not abandoned. It was created primarily to bring Routerify up to date with the latest Hyper API after the original Routerify project stopped being maintained.
The main goal of Routerify-NG has been achieved: it works with modern Hyper and provides the routing API that Routerify users are familiar with.
Because of that, there isn't much reason for me to constantly add changes or features just to keep the repository active. If the current version works, there's nothing that needs changing.
So if you see that the repository hasn't had commits recently, that's intentional, not abandonment.
If Hyper introduces breaking changes, something stops working, or there's a meaningful improvement that should be made, I'm happy to maintain Routerify-NG and update it when needed.
- Build complex routing with scopes and middlewares
- Fully compatible with Hyper 1.x and Tokio 1.x
- Fast route matching via
RegexSet - Middleware system with shared state between routes
- Robust error handling
WebSocketsupport compatible with Hyper 1.x- Extensive documentation and examples
| Framework | Language | Requests/sec |
|---|---|---|
| Hyper 1.7 | Rust 2024 | 160 000 + |
| Routerify-NG (Hyper 1.7) | Rust 2024 | 158 000 + |
| Actix-Web 4 | Rust 2024 | 150 000 + |
| Warp 0.3 | Rust 2024 | 145 000 + |
(benchmarks vary per system; see benchmarks folder)
Add this to your Cargo.toml:
[dependencies]
routerify_ng = "0.1.0"
hyper = "1.7"
tokio = { version = "1", features = ["full"] }use http_body_util::Full;
use hyper::body::Incoming;
use hyper::service::Service;
use hyper::{Request, Response, StatusCode};
use hyper_util::rt::TokioExecutor;
use hyper_util::rt::TokioIo;
use hyper_util::server::conn::auto::Builder;
use routerify_ng::prelude::*;
use routerify_ng::{Middleware, RequestInfo, Router, RouterService};
use std::sync::Arc;
use std::{convert::Infallible, net::SocketAddr};
use tokio::net::TcpListener;
struct State(u64);
async fn home_handler(
req: Request<Incoming>,
) -> Result<Response<Full<hyper::body::Bytes>>, Infallible> {
Ok(Response::new(Full::new(
hyper::body::Bytes::from("Home page"),
)))
}
async fn user_handler(
req: Request<Incoming>,
) -> Result<Response<Full<hyper::body::Bytes>>, Infallible> {
let user_id = req.param("userId").unwrap();
Ok(Response::new(Full::new(
hyper::body::Bytes::from(format!("Hello {}", user_id)),
)))
}
async fn logger(req: Request<Incoming>) -> Result<Request<Incoming>, Infallible> {
println!("{} {} {}", req.remote_addr(), req.method(), req.uri().path());
Ok(req)
}
async fn error_handler(
err: routerify_ng::RouteError,
_: RequestInfo,
) -> Response<Full<hyper::body::Bytes>> {
eprintln!("{}", err);
Response::builder()
.status(StatusCode::INTERNAL_SERVER_ERROR)
.body(Full::new(hyper::body::Bytes::from(format!(
"Something went wrong: {}",
err
))))
.unwrap()
}
fn router() -> Router<Incoming, Infallible> {
Router::builder()
.middleware(Middleware::pre(logger))
.get("/", home_handler)
.get("/users/:userId", user_handler)
.err_handler_with_info(error_handler)
.build()
.unwrap()
}
#[tokio::main]
async fn main() {
let router = router();
let router_service = Arc::new(RouterService::new(router).unwrap());
let addr = SocketAddr::from(([127, 0, 0, 1], 3000));
let listener = TcpListener::bind(addr).await.unwrap();
println!("App is running on: {}", addr);
loop {
match listener.accept().await {
Ok((stream, _)) => {
let router_service = Arc::clone(&router_service);
tokio::task::spawn(async move {
let request_service = router_service.call(&stream).await.unwrap();
let io = TokioIo::new(stream);
let builder = Builder::new(TokioExecutor::new());
if let Err(err) = builder.serve_connection(io, request_service).await {
eprintln!("Error serving connection: {:?}", err);
}
});
}
Err(e) => {
eprintln!("Error accepting connection: {}", e);
}
}
}
}Docs for exhaustive documentation.
Find runnable examples in the examples directory.
Routerify-NG is primarily a compatibility and maintenance project.
The original Routerify project stopped being maintained, while Hyper continued to evolve. Routerify-NG exists to bridge that gap and keep the Routerify API usable with modern versions of Hyper.
There is no need for constant development when the project already does what it was built to do.
If a future Hyper release introduces breaking changes, something stops working, or there is a meaningful improvement worth making, contributions are welcome. Open an issue or submit a pull request and I'll take a look.
Licensed under the MIT License.
Routerify-NG — keeping Routerify simple, fast, and usable with modern Hyper.