{"id":20540569,"url":"https://github.com/utopia-php/http","last_synced_at":"2026-04-12T16:27:54.729Z","repository":{"id":38400039,"uuid":"183800584","full_name":"utopia-php/http","owner":"utopia-php","description":"Lite \u0026 fast micro PHP HTTP framework that is easy to learn.","archived":false,"fork":false,"pushed_at":"2026-02-19T14:04:58.000Z","size":1403,"stargazers_count":294,"open_issues_count":17,"forks_count":36,"subscribers_count":14,"default_branch":"master","last_synced_at":"2026-02-19T16:27:15.823Z","etag":null,"topics":["framework","hacktoberfest","micro-framework","php","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/utopia-php.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.md","code_of_conduct":"CODE_OF_CONDUCT.md","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,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2019-04-27T17:08:23.000Z","updated_at":"2026-02-19T14:04:24.000Z","dependencies_parsed_at":"2026-02-19T14:03:35.500Z","dependency_job_id":null,"html_url":"https://github.com/utopia-php/http","commit_stats":{"total_commits":530,"total_committers":21,"mean_commits":"25.238095238095237","dds":0.7415094339622641,"last_synced_commit":"f21fd86c049d5fda711e966e9cd926386c36df0d"},"previous_names":["utopia-php/http"],"tags_count":168,"template":false,"template_full_name":null,"purl":"pkg:github/utopia-php/http","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/utopia-php%2Fhttp","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/utopia-php%2Fhttp/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/utopia-php%2Fhttp/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/utopia-php%2Fhttp/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/utopia-php","download_url":"https://codeload.github.com/utopia-php/http/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/utopia-php%2Fhttp/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30040231,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-03T06:58:30.252Z","status":"ssl_error","status_checked_at":"2026-03-03T06:58:15.329Z","response_time":61,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":["framework","hacktoberfest","micro-framework","php","router"],"created_at":"2024-11-16T01:16:14.055Z","updated_at":"2026-03-03T10:00:40.738Z","avatar_url":"https://github.com/utopia-php.png","language":"PHP","readme":"\u003cp\u003e\n    \u003cimg height=\"45\" src=\"docs/logo.png\" alt=\"Logo\"\u003e\n\u003c/p\u003e\n\n[![Build Status](https://travis-ci.org/utopia-php/http.svg?branch=master)](https://travis-ci.org/utopia-php/http)\n![Total Downloads](https://img.shields.io/packagist/dt/utopia-php/http.svg)\n[![Discord](https://img.shields.io/discord/564160730845151244?label=discord)](https://discord.gg/GSeTUeA)\n\nUtopia HTTP is a PHP MVC based framework with minimal must-have features for professional, simple, advanced and secure web development. This library is maintained by the [Appwrite team](https://appwrite.io).\n\nUtopia HTTP is *almost* dependency-free. Any extra features, such as authentication or caching are available as standalone models in order to keep the framework core clean, light, and easy to learn.\n\n## Getting Started\n\nInstall using Composer:\n\n```bash\ncomposer require utopia-php/http\n```\n\nInit your first application in `src/server.php`:\n\n\n```php\nrequire_once __DIR__.'/../vendor/autoload.php';\n\nuse Utopia\\DI\\Container;\nuse Utopia\\DI\\Dependency;\nuse Utopia\\Http\\Http;\nuse Utopia\\Http\\Request;\nuse Utopia\\Http\\Response;\nuse Utopia\\Http\\Adapter\\FPM\\Server;\n\n// Creating the dependency injection container\n$container = new Container();\n\n// Adding a user dependency to the container\n$user = new Dependency();\n$user\n    -\u003esetName('user')\n    -\u003einject('request') // We can insert and use other injections as well\n    -\u003esetCallback(fn (Request $request) =\u003e $request-\u003egetHeader('x-user-id', 'John Doe'));\n\n$container-\u003eset($user);\n\n// Defining Route\nHttp::get('/hello-world')\n    -\u003einject('request')  // Auto-injected each request\n    -\u003einject('response') // Auto-injected each request\n    -\u003einject('user')\n    -\u003eaction(\n        function(Request $request, Response $response, string $user) {\n            $response\n              -\u003eaddHeader('Cache-Control', 'no-cache, no-store, must-revalidate')\n              -\u003eaddHeader('Expires', '0')\n              -\u003eaddHeader('Pragma', 'no-cache')\n              -\u003ejson(['message' =\u003e 'Hello World', 'user' =\u003e $user]);\n        }\n    );\n\nHttp::setMode(Http::MODE_TYPE_PRODUCTION);\n\n$http = new Http(new Server(), $container, 'America/New_York');\n$http-\u003estart();\n```\n\nRun HTTP server:\n\n```bash\nphp -S localhost:8000 src/server.php\n```\n\nSend HTTP request:\n\n```bash\ncurl http://localhost:8000/hello-world\n```\n\n### Server Adapters\n\nThe library supports server adapters to be able to run on any PHP setup. You could use the FPM or Swoole server.\n\n#### Use PHP FPM server\n\n```php\nuse Utopia\\DI\\Container;\nuse Utopia\\Http\\Http;\nuse Utopia\\Http\\Response;\nuse Utopia\\Http\\Adapter\\FPM\\Server;\n\nHttp::get('/')\n    -\u003einject('response')\n    -\u003eaction(\n        function(Response $response) {\n            $response-\u003esend('Hello from PHP FPM');\n        }\n    );\n\n$http = new Http(new Server(), new Container(), 'America/New_York');\n$http-\u003estart();\n```\n\n\u003e When using PHP FPM, you can use the command `php -S localhost:80 src/server.php` to run the HTTP server locally\n\n#### Using Swoole server\n\n```php\nuse Utopia\\DI\\Container;\nuse Utopia\\Http\\Http;\nuse Utopia\\Http\\Request;\nuse Utopia\\Http\\Response;\nuse Utopia\\Http\\Adapter\\Swoole\\Server;\n\nHttp::get('/')\n    -\u003einject('request')\n    -\u003einject('response')\n    -\u003eaction(\n        function(Request $request, Response $response) {\n            $response-\u003esend('Hello from Swoole');\n        }\n    );\n\n$http = new Http(new Server('0.0.0.0', '80' , ['open_http2_protocol' =\u003e true]), new Container(), 'America/New_York');\n$http-\u003estart();\n```\n\n\u003e When using Swoole, you can use the command `php src/server.php` to run the HTTP server locally, but you need Swoole installed. For setup with Docker, check out our [example application](/example)\n\n### Parameters\n\nParameters are used to receive input into endpoint action from the HTTP request. Parameters could be defined as URL parameters or in a body with a structure such as JSON.\n\nEvery parameter must have a validator defined. Validators are simple classes that verify the input and ensure the security of inputs. You can define your own validators or use some of [built-in validators](https://github.com/utopia-php/validators).\n\nDefine an endpoint with params:\n\n```php\nHttp::get('/')\n    -\u003eparam('name', 'World', new Text(256), 'Name to greet. Optional, max length 256.', true)\n    -\u003einject('response')\n    -\u003eaction(function(string $name, Response $response) {\n        $response-\u003esend('Hello ' . $name);\n    });\n```\n\nSend HTTP requests to ensure the parameter works:\n\n```bash\ncurl http://localhost:8000/hello-world\ncurl http://localhost:8000/hello-world?name=Utopia\ncurl http://localhost:8000/hello-world?name=Appwrite\n```\n\nIt's always recommended to use params instead of getting params or body directly from the request resource. If you do that intentionally, always make sure to run validation right after fetching such a raw input.\n\n### Hooks\n\nThere are three types of hooks:\n\n- **Init hooks** are executed before the route action is executed\n- **Shutdown hooks** are executed after route action is finished, but before application shuts down\n- **Error hooks** are executed whenever there's an error in the application lifecycle.\n\nYou can provide multiple hooks for each stage. If you do not assign groups to the hook, by default, the hook will be executed for every route. If a group is defined on a hook, it will only run during the lifecycle of a request with the same group name on the action.\n\n```php\nHttp::init()\n    -\u003einject('request')\n    -\u003eaction(function(Request $request) {\n        \\var_dump(\"Recieved: \" . $request-\u003egetMethod() . ' ' . $request-\u003egetURI());\n    });\n\nHttp::shutdown()\n    -\u003einject('response')\n    -\u003eaction(function(Response $response) {\n        \\var_dump('Responding with status code: ' . $response-\u003egetStatusCode());\n    });\n\nHttp::error()\n    -\u003einject('error')\n    -\u003einject('response')\n    -\u003eaction(function(\\Throwable $error, Response $response) {\n        $response\n            -\u003esetStatusCode(500)\n            -\u003esend('Error occurred ' . $error);\n    });\n```\n\nHooks are designed to be actions that run during the lifecycle of requests. Hooks should include functional logic. Hooks are not designed to prepare dependencies or context for the request. For such a use case, you should use resources.\n\n### Groups\n\nGroups allow you to define common behavior for multiple endpoints.\n\nYou can start by defining a group on an endpoint. Keep in mind you can also define multiple groups on a single endpoint.\n\n```php\nHttp::get('/v1/health')\n    -\u003egroups(['api', 'public'])\n    -\u003einject('response')\n    -\u003eaction(\n        function(Response $response) {\n            $response-\u003esend('OK');\n        }\n    );\n```\n\nNow you can define hooks that would apply only to specific groups. Remember, hooks can also be assigned to multiple groups.\n\n```php\nHttp::init()\n    -\u003egroups(['api'])\n    -\u003einject('request')\n    -\u003einject('response')\n    -\u003eaction(function(Request $request, Response $response) {\n        $apiKey = $request-\u003egetHeader('x-api-key', '');\n\n        if(empty($apiKey)) {\n            $response\n                -\u003esetStatusCode(Response::STATUS_CODE_UNAUTHORIZED)\n                -\u003esend('API key missing.');\n        }\n    });\n```\n\nGroups are designed to be actions that run during the lifecycle of requests to endpoints that have some logic in common. Groups allow you to prevent code duplication and are designed to be defined anywhere in your source code to allow flexibility.\n\n### Injections\n\nInjections allow you to prepare dependencies for requests such as database connection or the user who sent the request. A new instance of a resource is created for every request.\n\nWe define an injection using a Container:\n\n```php\nuse Utopia\\DI\\Container;\nuse Utopia\\DI\\Dependency;\n\n$container = new Container();\n\n$timing = new Dependency();\n$timing\n    -\u003esetName('timing')\n    -\u003esetCallback(fn () =\u003e \\microtime(true));\n\n$container-\u003eadd($timing);\n```\n\nInject resource into endpoint action:\n\n```php\nHttp::get('/')\n    -\u003einject('timing')\n    -\u003einject('response')\n    -\u003eaction(function(float $timing, Response $response) {\n        $response-\u003esend('Request Unix timestamp: ' . \\strval($timing));\n    });\n```\n\nInject resource into a hook:\n\n```php\nHttp::shutdown()\n    -\u003einject('timing')\n    -\u003eaction(function(float $timing) {\n        $difference = \\microtime(true) - $timing;\n        \\var_dump(\"Request took: \" . $difference . \" seconds\");\n    });\n```\n\nIn advanced scenarios, resources can also be injected into other resources or endpoint parameters.\n\nResources are designed to prepare dependencies or context for the request. Resources are not meant to do functional logic or return callbacks. For such a use case, you should use hooks.\n\nTo learn more about architecture and features for this library, check out more in-depth [Getting started guide](/docs/Getting-Starting-Guide.md).\n\n## System Requirements\n\nUtopia Framework requires PHP 8.1 or later. We recommend using the latest PHP version whenever possible.\n\n## More from Utopia\n\nOur ecosystem supports other thin PHP projects aiming to extend the core PHP Utopia HTTP.\n\nEach project is focused on solving a single, very simple problem and you can use composer to include any of them in your next project.\n\nYou can find all libraries in [GitHub Utopia organization](https://github.com/utopia-php).\n\n## Contributing\n\nAll code contributions - including those of people having commit access - must go through a pull request and approved by a core developer before being merged. This is to ensure proper review of all the code.\n\nFork the project, create a feature branch, and send us a pull request.\n\nYou can refer to the [Contributing Guide](https://github.com/utopia-php/http/blob/master/CONTRIBUTING.md) for more info.\n\nFor security issues, please email security@appwrite.io instead of posting a public issue in GitHub.\n\n## Copyright and license\n\nThe MIT License (MIT) [http://www.opensource.org/licenses/mit-license.php](http://www.opensource.org/licenses/mit-license.php)\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Futopia-php%2Fhttp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Futopia-php%2Fhttp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Futopia-php%2Fhttp/lists"}