{"id":18794584,"url":"https://github.com/effectra/router","last_synced_at":"2025-10-09T00:08:44.521Z","repository":{"id":167964689,"uuid":"643586884","full_name":"effectra/router","owner":"effectra","description":"Effectra/Router is a versatile PHP routing library for web applications. It offers flexible route handling, HTTP method support, and parameter mapping to controllers or closures. With middleware, route grouping, and scalability, it simplifies route management. Essential for PHP developers building APIs or web apps.","archived":false,"fork":false,"pushed_at":"2024-01-03T23:30:50.000Z","size":56,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-10-09T00:06:22.883Z","etag":null,"topics":["http","middleware","php","psr","psr-15","psr-7","router"],"latest_commit_sha":null,"homepage":"","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/effectra.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":"2023-05-21T16:26:27.000Z","updated_at":"2023-07-18T09:28:44.000Z","dependencies_parsed_at":"2024-01-04T01:43:32.790Z","dependency_job_id":null,"html_url":"https://github.com/effectra/router","commit_stats":null,"previous_names":["effectra/router"],"tags_count":11,"template":false,"template_full_name":null,"purl":"pkg:github/effectra/router","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/effectra%2Frouter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/effectra%2Frouter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/effectra%2Frouter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/effectra%2Frouter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/effectra","download_url":"https://codeload.github.com/effectra/router/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/effectra%2Frouter/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279000745,"owners_count":26082879,"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","status":"online","status_checked_at":"2025-10-08T02:00:06.501Z","response_time":56,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["http","middleware","php","psr","psr-15","psr-7","router"],"created_at":"2024-11-07T21:29:51.045Z","updated_at":"2025-10-09T00:08:44.506Z","avatar_url":"https://github.com/effectra.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Effectra Router Library\n\nEffectra PHP Router is a lightweight and flexible routing library for PHP applications. It provides a convenient way to define routes and dispatch incoming requests to the appropriate controllers or callbacks.\n\n## Installation\n\nYou can install the Effectra PHP Router library via Composer. Run the following command in your project directory:\n\n```\ncomposer require effectra/router\n```\n\n## Usage\n\nTo get started with Effectra PHP Router, follow these steps:\n\n1. Include the autoloader if you haven't already done so:\n\n```php\nrequire_once 'vendor/autoload.php';\n```\n\n2. Import the necessary classes:\n\n```php\nuse Effectra\\Router\\Route;\nuse Effectra\\Router\\RouteGroup;\n\nuse Effectra\\Http\\Foundation\\RequestFoundation;\nuse Effectra\\Http\\Message\\Response;\n\nuse Psr\\Http\\Message\\RequestInterface;\nuse Psr\\Http\\Message\\ResponseInterface;\n```\n\n3. Create an instance of the `Route` class:\n\n```php\n//pass response class to the router\n$response = new Response();\n\n$route = new Route($response);\n```\n\n4. Define routes using the available methods:\n\n```php\n$route-\u003eget('/home', function () {\n    return 'Welcome to the home page!';\n});\n\n$route-\u003epost('/contact', 'StaticController@login');\n\n$router-\u003eget('/', [HomeController::class, 'index']);\n\n$router-\u003eget('/users/', [UserController::class, 'index']);\n\n\n$router-\u003epost('/signin', function (RequestInterface $request, ResponseInterface $response) {\n    return $response-\u003ejson([\n        'message' =\u003e 'hello world'\n    ]);\n});\n\n$route-\u003ecrud('/report', ReportController::class, 'read|readOne|create|delete|deleteAll|search');\n\n$route-\u003eauth('/auth/', AuthController::class);\n\n$route-\u003egroup('/file/upload/', UploadController::class, function(RouteGroup $router){\n    $router-\u003epost('audio','createAudio');\n    $router-\u003epost('video','createVideo');\n});\n```\n\n5. Dispatch the incoming request:\n\n```php\n\n$request = RequestFoundation::createFromGlobals();\n\n$route-\u003edispatch($request);\n```\n\n### Route Methods\n\nThe `Route` class provides several methods to define routes:\n\n- `get($pattern, $callback)`: Defines a GET route.\n- `post($pattern, $callback)`: Defines a POST route.\n- `put($pattern, $callback)`: Defines a PUT route.\n- `delete($pattern, $callback)`: Defines a DELETE route.\n- `patch($pattern, $callback)`: Defines a PATCH route.\n- `options($pattern, $callback)`: Defines an OPTIONS route.\n- `any($pattern, $callback)`: Defines a route that matches any HTTP method.\n- `register($method, $pattern, $callback)`: Defines a custom route with a specific HTTP method.\n- `routes()`: Returns an array of defined routes.\n\n### Middleware\n\nThe `Route` class supports middleware for route groups. You can use the `middleware` method to add middleware to a group of routes:\n\n```php\n$router-\u003eget('/users/{id}', [UserController::class, 'show'])-\u003emiddleware(new AuthMiddleware());\n\n```\n\n### Error Handling\n\nThe `Route` class provides methods to handle 404 Not Found and 500 Internal Server Error responses:\n\n```php\n$route-\u003esetNotFound(function () {\n    // Handle 404 Not Found response\n});\n\n$route-\u003esetInternalServerError(function () {\n    // Handle 500 Internal Server Error response\n});\n```\n\n## Contributing\n\nContributions to the Effectra PHP Router library are welcome! If you encounter any issues or have suggestions for improvements, please feel free to open an issue or submit a pull request.\n\n## License\n\nThe Effectra PHP Router library is open-source software licensed under the [MIT license](https://opensource.org/licenses/MIT).\n\n---","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feffectra%2Frouter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Feffectra%2Frouter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feffectra%2Frouter/lists"}