Routerify
Routerify
provides a lightweight, idiomatic, composable and modular router implementation with middleware support for the Rust HTTP library hyper.
Routerify's core features:
- 🌀 Design complex routing using scopes and middlewares
- 🚀 Fast route matching using
RegexSet
- 🍺 Route handlers may return any HttpBody
- ❗ Flexible error handling strategy
- 💁
WebSocket
support out of the box. - 🔥 Route handlers and middleware may share state
- 🍗 Extensive documentation and examples
To generate a quick server app using Routerify and hyper, please check out hyper-routerify-server-template.
Benchmarks
Framework | Language | Requests/sec |
---|---|---|
hyper v0.14 | Rust 1.50.0 | 144,583 |
routerify v2.0.0 with hyper v0.14 | Rust 1.50.0 | 144,621 |
actix-web v3 | Rust 1.50.0 | 131,292 |
warp v0.3 | Rust 1.50.0 | 145,362 |
go-httprouter, branch master | Go 1.16 | 130,662 |
Rocket, branch master | Rust 1.50.0 | 130,045 |
For more info, please visit Benchmarks.
Install
Add this to your Cargo.toml
file:
[]
= "2.0.0"
= "0.14"
= { = "1", = ["full"] }
Basic Example
A simple example using Routerify
with hyper
would look like the following:
use ;
// Import the routerify prelude traits.
use *;
use ;
use ;
// Define an app state to share it across the route handlers and middlewares.
;
// A handler for "/" page.
async
// A handler for "/users/:userId" page.
async
// A middleware which logs an http request.
async
// Define an error handler function which will accept the `routerify::Error`
// and the request information and generates an appropriate response.
async
// Create a `Router<Body, Infallible>` for response body type `hyper::Body`
// and for handler error type `Infallible`.
async
Documentation
Please visit: Docs for an exhaustive documentation.
Examples
The examples.
Contributing
Your PRs and suggestions are always welcome.