{"id":19374711,"url":"https://github.com/gyselroth/micro-http","last_synced_at":"2026-06-20T07:31:10.628Z","repository":{"id":62513745,"uuid":"111522936","full_name":"gyselroth/micro-http","owner":"gyselroth","description":"DEPRECATED!","archived":false,"fork":false,"pushed_at":"2020-01-13T15:11:01.000Z","size":2567,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2026-05-28T22:06:17.823Z","etag":null,"topics":["http-router","php"],"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/gyselroth.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-11-21T08:48:57.000Z","updated_at":"2020-01-13T15:10:37.000Z","dependencies_parsed_at":"2022-11-02T13:15:32.545Z","dependency_job_id":null,"html_url":"https://github.com/gyselroth/micro-http","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"purl":"pkg:github/gyselroth/micro-http","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gyselroth%2Fmicro-http","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gyselroth%2Fmicro-http/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gyselroth%2Fmicro-http/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gyselroth%2Fmicro-http/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gyselroth","download_url":"https://codeload.github.com/gyselroth/micro-http/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gyselroth%2Fmicro-http/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34561766,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-20T02:00:06.407Z","response_time":98,"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-router","php"],"created_at":"2024-11-10T08:35:55.984Z","updated_at":"2026-06-20T07:31:10.612Z","avatar_url":"https://github.com/gyselroth.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Lightweight HTTP routing\n\n[![Build Status](https://travis-ci.org/gyselroth/micro-http.svg?branch=master)](https://travis-ci.org/gyselroth/micro-http)\n[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/gyselroth/micro-http/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/gyselroth/micro-http/?branch=master)\n[![Latest Stable Version](https://img.shields.io/packagist/v/gyselroth/micro-http.svg)](https://packagist.org/packages/gyselroth/micro-http)\n[![GitHub release](https://img.shields.io/github/release/gyselroth/micro-http.svg)](https://github.com/gyselroth/micro-http/releases)\n[![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://raw.githubusercontent.com/gyselroth/micro-http/master/LICENSE)\n\n## Description\n\n## Requirements\nThe component is only \u003e= PHP7.1 compatible.\n\n## Download\nThe package is available at packagist: https://packagist.org/packages/gyselroth/micro-http\n\nTo install the package via composer execute:\n```\ncomposer require gyselroth/micro-http\n```\n\n## Documentation\n\n### Initialize router\nThe http router requires an array with http headers, usually this is $_SERVER and a PSR-3 compatible logger.\n\n```php\n$router = new \\Micro\\Http\\Router(\\Psr\\Log\\LoggerInterface $logger, array $server, ?\\Psr\\Container\\ContainerInterface);\n```\n\n### Adding routes\n\n```php\n$router = (new \\Micro\\Http\\Router($logger))\n  -\u003eclearRoutingTable()\n  -\u003eaddRoute(new \\Micro\\Http\\Router\\Route('/api/v1/user', 'MyApp\\Rest\\v1\\User'))\n  -\u003eaddRoute(new \\Micro\\Http\\Router\\Route('/api/v1/user/{uid:#([0-9a-z]{24})#}', 'MyApp\\Rest\\v1\\User'))\n  -\u003eaddRoute(new \\Micro\\Http\\Router\\Route('/api/v1$', 'MyApp\\Rest\\v1\\Rest'))\n  -\u003eaddRoute(new \\Micro\\Http\\Router\\Route('/api/v1', 'MyApp\\Rest\\v1\\Rest'))\n  -\u003eaddRoute(new \\Micro\\Http\\Router\\Route('/api$', 'MyApp\\Rest\\v1\\Rest'));\n  -\u003erun(array $controller_params);\n```\n\nThe router tries to map a request to the first matching route in his routing table. The request gets mappend to a class and method. Optional parameters/query string gets automatically submitted to the final controller class.\n\nGiven the routing table above and the following final controller class:\n\n```php\nnamespace MyApp\\Rest\\v1;\n\nclass User\n{\n    /**\n     * GET http://localhost/api/v1/user/540f1fc9a641e6eb708b4618/attributes\n     * GET http://localhost/api/v1/user/attributes?uid=540f1fc9a641e6eb708b4618\n     */\n    public function getAttributes(string $uid=null): \\Micro\\Http\\Response\n    {\n\n    }\n\n    /**\n     * GET http://localhost/api/v1/user/540f1fc9a641e6eb708b4618\n     * GET http://localhost/api/v1/user?uid=540f1fc9a641e6eb708b4618\n     */\n    public function get(string $uid=null): \\Micro\\Http\\Response\n    {\n\n    }\n\n    /**\n     * POST http://localhost/api/v1/user/540f1fc9a641e6eb708b4618/password / POST body password=1234\n     * POST http://localhost/api/v1/user/password?uid=540f1fc9a641e6eb708b4618 / POST body password=1234\n     * POST http://localhost/api/v1/user/password / POST body password=1234, uid=540f1fc9a641e6eb708b4618\n     */\n    public function postPassword(string $uid, string $password): \\Micro\\Http\\Response\n    {\n\n    }\n\n    /**\n     * DELETE http://localhost/api/v1/user/540f1fc9a641e6eb708b4618/mail\n     * DELETE http://localhost/api/v1/user/mail?uid=540f1fc9a641e6eb708b4618\n     */\n    public function deleteMail(string $uid=null): \\Micro\\Http\\Response\n    {\n\n    }\n\n    /**\n     * DELETE http://localhost/api/v1/540f1fc9a641e6eb708b4618/mail\n     * DELETE http://localhost/api/v1/user?uid=540f1fc9a641e6eb708b4618\n     */\n    public function delete(string $uid=null): \\Micro\\Http\\Response\n    {\n\n    }\n\n    /**\n     * HEAD http://localhost/api/v1/user/540f1fc9a641e6eb708b4618\n     * HEAD http://localhost/api/v1/user?uid=540f1fc9a641e6eb708b4618\n     */\n    public function headExists(string $uid=null): \\Micro\\Http\\Response\n    {\n\n    }\n}\n```\n\n### Response\nEach endpoint needs to return a Response object to the router.\n\n```php\n/**\n * HEAD http://localhost/api/v1/user/540f1fc9a641e6eb708b4618\n * HEAD http://localhost/api/v1/user?uid=540f1fc9a641e6eb708b4618\n */\npublic function headExists(string $uid=null): \\Micro\\Http\\Response\n{\n  if(true) {\n    return (new \\Micro\\Http\\Response())-\u003esetCode(200)-\u003esetBody('user does exists');\n  } else {\n    return (new \\Micro\\Http\\Response())-\u003esetCode(404);  \n  }\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgyselroth%2Fmicro-http","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgyselroth%2Fmicro-http","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgyselroth%2Fmicro-http/lists"}