{"id":13711858,"url":"https://github.com/middlewares/fast-route","last_synced_at":"2026-01-07T23:54:52.541Z","repository":{"id":52227126,"uuid":"70397123","full_name":"middlewares/fast-route","owner":"middlewares","description":"PSR-15 middleware to use FastRoute","archived":false,"fork":false,"pushed_at":"2025-03-26T14:44:07.000Z","size":57,"stargazers_count":96,"open_issues_count":0,"forks_count":7,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-04-26T14:59:38.988Z","etag":null,"topics":["fastroute","http","middleware","psr-15","router"],"latest_commit_sha":null,"homepage":null,"language":"PHP","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/middlewares.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-10-09T10:55:20.000Z","updated_at":"2025-03-23T10:31:49.000Z","dependencies_parsed_at":"2022-09-11T09:53:14.974Z","dependency_job_id":null,"html_url":"https://github.com/middlewares/fast-route","commit_stats":null,"previous_names":[],"tags_count":15,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/middlewares%2Ffast-route","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/middlewares%2Ffast-route/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/middlewares%2Ffast-route/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/middlewares%2Ffast-route/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/middlewares","download_url":"https://codeload.github.com/middlewares/fast-route/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252772172,"owners_count":21801866,"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":["fastroute","http","middleware","psr-15","router"],"created_at":"2024-08-02T23:01:12.363Z","updated_at":"2026-01-07T23:54:52.499Z","avatar_url":"https://github.com/middlewares.png","language":"PHP","funding_links":[],"categories":["Packages"],"sub_categories":["Router"],"readme":"# middlewares/fast-route\n\n[![Latest Version on Packagist][ico-version]][link-packagist]\n[![Software License][ico-license]](LICENSE)\n![Testing][ico-ga]\n[![Total Downloads][ico-downloads]][link-downloads]\n\nMiddleware to use [FastRoute](https://github.com/nikic/FastRoute) for handler discovery.\n\n## Requirements\n\n* PHP \u003e= 7.2\n* A [PSR-7 http library](https://github.com/middlewares/awesome-psr15-middlewares#psr-7-implementations)\n* A [PSR-15 middleware dispatcher](https://github.com/middlewares/awesome-psr15-middlewares#dispatcher)\n\n## Installation\n\nThis package is installable and autoloadable via Composer as [middlewares/fast-route](https://packagist.org/packages/middlewares/fast-route).\n\n```sh\ncomposer require middlewares/fast-route\n```\n\nYou may also want to install [middlewares/request-handler](https://packagist.org/packages/middlewares/request-handler).\n\n## Example\n\nThis example uses [middlewares/request-handler](https://github.com/middlewares/request-handler) to execute the route handler:\n\n```php\n//Create the router dispatcher\n$dispatcher = FastRoute\\simpleDispatcher(function (FastRoute\\RouteCollector $r) {\n    $r-\u003eaddRoute('GET', '/hello/{name}', function ($request) {\n        //The route parameters are stored as attributes\n        $name = $request-\u003egetAttribute('name');\n\n        //You can echo the output (it will be captured and written into the body)\n        echo sprintf('Hello %s', $name);\n\n        //Or return a string\n        return sprintf('Hello %s', $name);\n\n        //Or return a response\n        return new Response();\n    });\n});\n\n$dispatcher = new Dispatcher([\n    new Middlewares\\FastRoute($dispatcher),\n    new Middlewares\\RequestHandler()\n]);\n\n$response = $dispatcher-\u003edispatch(new ServerRequest('/hello/world'));\n```\n\n**FastRoute** allows anything to be defined as the router handler (a closure, callback, action object, controller class, etc). The middleware will store this handler in a request attribute.\n\n## Usage\n\nCreate the middleware with a `FastRoute\\Dispatcher` instance:\n\n```php\n$route = new Middlewares\\FastRoute($dispatcher);\n```\n\nOptionally, you can provide a `Psr\\Http\\Message\\ResponseFactoryInterface` as the second argument, that will be used to create the error responses (`404` or `405`). If it's not defined, [Middleware\\Utils\\Factory](https://github.com/middlewares/utils#factory) will be used to detect it automatically.\n\n```php\n$responseFactory = new MyOwnResponseFactory();\n\n$route = new Middlewares\\FastRoute($dispatcher, $responseFactory);\n```\n\n### attribute\n\nChanges the attribute name used to store the handler in the server request. The default name is `request-handler`.\n\n```php\n$dispatcher = new Dispatcher([\n    //Save the route handler in an attribute called \"route\"\n    (new Middlewares\\FastRoute($dispatcher))-\u003eattribute('route'),\n\n    //Execute the route handler\n    (new Middlewares\\RequestHandler())-\u003ehandlerAttribute('route')\n]);\n```\n\n---\n\nPlease see [CHANGELOG](CHANGELOG.md) for more information about recent changes and [CONTRIBUTING](CONTRIBUTING.md) for contributing details.\n\nThe MIT License (MIT). Please see [LICENSE](LICENSE) for more information.\n\n[ico-version]: https://img.shields.io/packagist/v/middlewares/fast-route.svg?style=flat-square\n[ico-license]: https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square\n[ico-ga]: https://github.com/middlewares/fast-route/workflows/testing/badge.svg\n[ico-downloads]: https://img.shields.io/packagist/dt/middlewares/fast-route.svg?style=flat-square\n\n[link-packagist]: https://packagist.org/packages/middlewares/fast-route\n[link-downloads]: https://packagist.org/packages/middlewares/fast-route\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmiddlewares%2Ffast-route","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmiddlewares%2Ffast-route","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmiddlewares%2Ffast-route/lists"}