{"id":13672470,"url":"https://github.com/routerify/routerify","last_synced_at":"2025-05-15T09:07:31.140Z","repository":{"id":38095519,"uuid":"260275748","full_name":"routerify/routerify","owner":"routerify","description":"A lightweight, idiomatic, composable and modular router implementation with middleware support for the Rust HTTP library hyper.rs","archived":false,"fork":false,"pushed_at":"2024-02-22T05:39:54.000Z","size":355,"stargazers_count":392,"open_issues_count":19,"forks_count":33,"subscribers_count":7,"default_branch":"master","last_synced_at":"2025-04-15T05:18:34.267Z","etag":null,"topics":["cargo","http","hyper","hyper-rs","middleware","router","routerify","routing","rust"],"latest_commit_sha":null,"homepage":"https://docs.rs/routerify","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/routerify.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-04-30T17:33:08.000Z","updated_at":"2025-04-13T10:19:03.000Z","dependencies_parsed_at":"2024-06-18T20:14:35.563Z","dependency_job_id":null,"html_url":"https://github.com/routerify/routerify","commit_stats":{"total_commits":153,"total_committers":13,"mean_commits":11.76923076923077,"dds":0.326797385620915,"last_synced_commit":"0707951ed48d2d4724e4b9332c81c40e30fc356d"},"previous_names":[],"tags_count":23,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/routerify%2Frouterify","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/routerify%2Frouterify/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/routerify%2Frouterify/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/routerify%2Frouterify/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/routerify","download_url":"https://codeload.github.com/routerify/routerify/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254310515,"owners_count":22049469,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cargo","http","hyper","hyper-rs","middleware","router","routerify","routing","rust"],"created_at":"2024-08-02T09:01:36.546Z","updated_at":"2025-05-15T09:07:26.121Z","avatar_url":"https://github.com/routerify.png","language":"Rust","readme":"\u003cdiv align=\"center\"\u003e\n  \u003ca href=\"https://github.com/routerify\"\u003e\n    \u003cimg width=\"200\" height=\"200\" src=\"https://avatars0.githubusercontent.com/u/64579326?s=200\u0026v=4\"\u003e\n  \u003c/a\u003e\n  \u003cbr /\u003e\n  \u003cbr /\u003e\n\u003c/div\u003e\n\n[![Github Actions Status](https://github.com/routerify/routerify/workflows/Test/badge.svg)](https://github.com/routerify/routerify/actions)\n[![crates.io](https://img.shields.io/crates/v/routerify.svg)](https://crates.io/crates/routerify)\n[![Documentation](https://docs.rs/routerify/badge.svg)](https://docs.rs/routerify)\n[![Contributors](https://img.shields.io/github/contributors/routerify/routerify.svg)](https://github.com/orgs/routerify/people)\n[![MIT](https://img.shields.io/crates/l/routerify.svg)](./LICENSE)\n\n# Routerify\n\n`Routerify` provides a lightweight, idiomatic, composable and modular router implementation with middleware support for the Rust HTTP library [hyper](https://hyper.rs/).\n\nRouterify's core features:\n\n- 🌀 Design complex routing using [scopes](https://github.com/routerify/routerify/blob/master/examples/scoped_router.rs) and [middlewares](https://github.com/routerify/routerify/blob/master/examples/middleware.rs)\n- 🚀 Fast route matching using [`RegexSet`](https://docs.rs/regex/1.4.3/regex/struct.RegexSet.html)\n- 🍺 Route handlers may return any [HttpBody](https://docs.rs/hyper/0.14.4/hyper/body/trait.HttpBody.html)\n- ❗ Flexible [error handling](https://github.com/routerify/routerify/blob/master/examples/error_handling_with_request_info.rs) strategy\n- 💁 [`WebSocket` support](https://github.com/routerify/routerify-websocket) out of the box.\n- 🔥 Route handlers and middleware [may share state](https://github.com/routerify/routerify/blob/master/examples/share_data_and_state.rs)\n- 🍗 [Extensive documentation](https://docs.rs/routerify/) and [examples](https://github.com/routerify/routerify/tree/master/examples)\n\n\nTo generate a quick server app using [Routerify](https://github.com/routerify/routerify) and [hyper](https://hyper.rs/), please check out [hyper-routerify-server-template](https://github.com/routerify/hyper-routerify-server-template).\n\n*Compiler support: requires rustc 1.48+*\n\n## Benchmarks\n\n| Framework      | Language    | Requests/sec |\n|----------------|-------------|--------------|\n| [hyper v0.14](https://github.com/hyperium/hyper) | Rust 1.50.0 | 144,583 |\n| [routerify v2.0.0](https://github.com/routerify/routerify) with [hyper v0.14](https://github.com/hyperium/hyper) | Rust 1.50.0 | 144,621 |\n| [actix-web v3](https://github.com/actix/actix-web) | Rust 1.50.0 | 131,292 |\n| [warp v0.3](https://github.com/seanmonstar/warp) | Rust 1.50.0 | 145,362 |\n| [go-httprouter, branch master](https://github.com/julienschmidt/httprouter) | Go 1.16 | 130,662 |\n| [Rocket, branch master](https://github.com/SergioBenitez/Rocket) | Rust 1.50.0 | 130,045 |\n\nFor more info, please visit [Benchmarks](https://github.com/routerify/routerify-benchmark).\n\n## Install\n\nAdd this to your `Cargo.toml` file:\n\n```toml\n[dependencies]\nrouterify = \"3\"\nhyper = \"0.14\"\ntokio = { version = \"1\", features = [\"full\"] }\n```\n\n## Basic Example\n\nA simple example using `Routerify` with `hyper` would look like the following:\n\n```rust\nuse hyper::{Body, Request, Response, Server, StatusCode};\n// Import the routerify prelude traits.\nuse routerify::prelude::*;\nuse routerify::{Middleware, Router, RouterService, RequestInfo};\nuse std::{convert::Infallible, net::SocketAddr};\n\n// Define an app state to share it across the route handlers and middlewares.\nstruct State(u64);\n\n// A handler for \"/\" page.\nasync fn home_handler(req: Request\u003cBody\u003e) -\u003e Result\u003cResponse\u003cBody\u003e, Infallible\u003e {\n    // Access the app state.\n    let state = req.data::\u003cState\u003e().unwrap();\n    println!(\"State value: {}\", state.0);\n\n    Ok(Response::new(Body::from(\"Home page\")))\n}\n\n// A handler for \"/users/:userId\" page.\nasync fn user_handler(req: Request\u003cBody\u003e) -\u003e Result\u003cResponse\u003cBody\u003e, Infallible\u003e {\n    let user_id = req.param(\"userId\").unwrap();\n    Ok(Response::new(Body::from(format!(\"Hello {}\", user_id))))\n}\n\n// A middleware which logs an http request.\nasync fn logger(req: Request\u003cBody\u003e) -\u003e Result\u003cRequest\u003cBody\u003e, Infallible\u003e {\n    println!(\"{} {} {}\", req.remote_addr(), req.method(), req.uri().path());\n    Ok(req)\n}\n\n// Define an error handler function which will accept the `routerify::Error`\n// and the request information and generates an appropriate response.\nasync fn error_handler(err: routerify::RouteError, _: RequestInfo) -\u003e Response\u003cBody\u003e {\n    eprintln!(\"{}\", err);\n    Response::builder()\n        .status(StatusCode::INTERNAL_SERVER_ERROR)\n        .body(Body::from(format!(\"Something went wrong: {}\", err)))\n        .unwrap()\n}\n\n// Create a `Router\u003cBody, Infallible\u003e` for response body type `hyper::Body`\n// and for handler error type `Infallible`.\nfn router() -\u003e Router\u003cBody, Infallible\u003e {\n    // Create a router and specify the logger middleware and the handlers.\n    // Here, \"Middleware::pre\" means we're adding a pre middleware which will be executed\n    // before any route handlers.\n    Router::builder()\n        // Specify the state data which will be available to every route handlers,\n        // error handler and middlewares.\n        .data(State(100))\n        .middleware(Middleware::pre(logger))\n        .get(\"/\", home_handler)\n        .get(\"/users/:userId\", user_handler)\n        .err_handler_with_info(error_handler)\n        .build()\n        .unwrap()\n}\n\n#[tokio::main]\nasync fn main() {\n    let router = router();\n\n    // Create a Service from the router above to handle incoming requests.\n    let service = RouterService::new(router).unwrap();\n\n    // The address on which the server will be listening.\n    let addr = SocketAddr::from(([127, 0, 0, 1], 3000));\n\n    // Create a server by passing the created service to `.serve` method.\n    let server = Server::bind(\u0026addr).serve(service);\n\n    println!(\"App is running on: {}\", addr);\n    if let Err(err) = server.await {\n        eprintln!(\"Server error: {}\", err);\n   }\n}\n```\n\n## Documentation\n\nPlease visit: [Docs](https://docs.rs/routerify) for an exhaustive documentation.\n\n## Examples\n\nThe [examples](https://github.com/routerify/routerify/tree/master/examples).\n\n## Contributing\n\nYour PRs and suggestions are always welcome.\n","funding_links":[],"categories":["Rust"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frouterify%2Frouterify","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frouterify%2Frouterify","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frouterify%2Frouterify/lists"}