PHPackages                             utopia-php/http - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Framework](/categories/framework)
4. /
5. utopia-php/http

ActiveLibrary[Framework](/categories/framework)

utopia-php/http
===============

A simple, light and advanced PHP HTTP framework

1.2.4(2w ago)2952.8k—0%36[2 issues](https://github.com/utopia-php/http/issues)[15 PRs](https://github.com/utopia-php/http/pulls)MITPHPPHP &gt;=8.1CI failing

Since Apr 28Pushed yesterday14 watchersCompare

[ Source](https://github.com/utopia-php/http)[ Packagist](https://packagist.org/packages/utopia-php/http)[ RSS](/packages/utopia-php-http/feed)WikiDiscussions master Synced today

READMEChangelog (10)Dependencies (9)Versions (300)Used By (0)

 [![Logo](docs/logo.png)](docs/logo.png)

[![Build Status](https://camo.githubusercontent.com/f8144d3c00656cacd56039c84d99f1770fb411f618c518332e4b17707312cddb/68747470733a2f2f7472617669732d63692e6f72672f75746f7069612d7068702f687474702e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/utopia-php/http)[![Total Downloads](https://camo.githubusercontent.com/d42911214801cdfa9248cbf6bdafb810f5682cfd03b8a871534396e705da8230/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f75746f7069612d7068702f687474702e737667)](https://camo.githubusercontent.com/d42911214801cdfa9248cbf6bdafb810f5682cfd03b8a871534396e705da8230/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f75746f7069612d7068702f687474702e737667)[![Discord](https://camo.githubusercontent.com/6e418910df1b6eb524c6cbd88dbaf5a5aa294316eeadcd963e11262a319f6321/68747470733a2f2f696d672e736869656c64732e696f2f646973636f72642f3536343136303733303834353135313234343f6c6162656c3d646973636f7264)](https://discord.gg/GSeTUeA)

Utopia 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).

Utopia 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.

Getting Started
---------------

[](#getting-started)

Install using Composer:

```
composer require utopia-php/http
```

Init your first application in `src/server.php`:

```
require_once __DIR__.'/../vendor/autoload.php';

use Utopia\DI\Container;
use Utopia\DI\Dependency;
use Utopia\Http\Http;
use Utopia\Http\Request;
use Utopia\Http\Response;
use Utopia\Http\Adapter\FPM\Server;

// Creating the dependency injection container
$container = new Container();

// Adding a user dependency to the container
$user = new Dependency();
$user
    ->setName('user')
    ->inject('request') // We can insert and use other injections as well
    ->setCallback(fn (Request $request) => $request->getHeader('x-user-id', 'John Doe'));

$container->set($user);

// Defining Route
Http::get('/hello-world')
    ->inject('request')  // Auto-injected each request
    ->inject('response') // Auto-injected each request
    ->inject('user')
    ->action(
        function(Request $request, Response $response, string $user) {
            $response
              ->addHeader('Cache-Control', 'no-cache, no-store, must-revalidate')
              ->addHeader('Expires', '0')
              ->addHeader('Pragma', 'no-cache')
              ->json(['message' => 'Hello World', 'user' => $user]);
        }
    );

Http::setMode(Http::MODE_TYPE_PRODUCTION);

$http = new Http(new Server(), $container, 'America/New_York');
$http->start();
```

Run HTTP server:

```
php -S localhost:8000 src/server.php
```

Send HTTP request:

```
curl http://localhost:8000/hello-world
```

### Server Adapters

[](#server-adapters)

The library supports server adapters to be able to run on any PHP setup. You could use the FPM or Swoole server.

#### Use PHP FPM server

[](#use-php-fpm-server)

```
use Utopia\DI\Container;
use Utopia\Http\Http;
use Utopia\Http\Response;
use Utopia\Http\Adapter\FPM\Server;

Http::get('/')
    ->inject('response')
    ->action(
        function(Response $response) {
            $response->send('Hello from PHP FPM');
        }
    );

$http = new Http(new Server(), new Container(), 'America/New_York');
$http->start();
```

> When using PHP FPM, you can use the command `php -S localhost:80 src/server.php` to run the HTTP server locally

#### Using Swoole server

[](#using-swoole-server)

```
use Utopia\DI\Container;
use Utopia\Http\Http;
use Utopia\Http\Request;
use Utopia\Http\Response;
use Utopia\Http\Adapter\Swoole\Server;

Http::get('/')
    ->inject('request')
    ->inject('response')
    ->action(
        function(Request $request, Response $response) {
            $response->send('Hello from Swoole');
        }
    );

$http = new Http(new Server('0.0.0.0', '80' , ['open_http2_protocol' => true]), new Container(), 'America/New_York');
$http->start();
```

> 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)

### Parameters

[](#parameters)

Parameters 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.

Every 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).

Define an endpoint with params:

```
Http::get('/')
    ->param('name', 'World', new Text(256), 'Name to greet. Optional, max length 256.', true)
    ->inject('response')
    ->action(function(string $name, Response $response) {
        $response->send('Hello ' . $name);
    });
```

Send HTTP requests to ensure the parameter works:

```
curl http://localhost:8000/hello-world
curl http://localhost:8000/hello-world?name=Utopia
curl http://localhost:8000/hello-world?name=Appwrite
```

It'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.

### Hooks

[](#hooks)

There are three types of hooks:

- **Init hooks** are executed before the route action is executed
- **Shutdown hooks** are executed after route action is finished, but before application shuts down
- **Error hooks** are executed whenever there's an error in the application lifecycle.

You 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.

```
Http::init()
    ->inject('request')
    ->action(function(Request $request) {
        \var_dump("Recieved: " . $request->getMethod() . ' ' . $request->getURI());
    });

Http::shutdown()
    ->inject('response')
    ->action(function(Response $response) {
        \var_dump('Responding with status code: ' . $response->getStatusCode());
    });

Http::error()
    ->inject('error')
    ->inject('response')
    ->action(function(\Throwable $error, Response $response) {
        $response
            ->setStatusCode(500)
            ->send('Error occurred ' . $error);
    });
```

Hooks 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.

### Groups

[](#groups)

Groups allow you to define common behavior for multiple endpoints.

You can start by defining a group on an endpoint. Keep in mind you can also define multiple groups on a single endpoint.

```
Http::get('/v1/health')
    ->groups(['api', 'public'])
    ->inject('response')
    ->action(
        function(Response $response) {
            $response->send('OK');
        }
    );
```

Now you can define hooks that would apply only to specific groups. Remember, hooks can also be assigned to multiple groups.

```
Http::init()
    ->groups(['api'])
    ->inject('request')
    ->inject('response')
    ->action(function(Request $request, Response $response) {
        $apiKey = $request->getHeader('x-api-key', '');

        if(empty($apiKey)) {
            $response
                ->setStatusCode(Response::STATUS_CODE_UNAUTHORIZED)
                ->send('API key missing.');
        }
    });
```

Groups 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.

### Injections

[](#injections)

Injections 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.

We define an injection using a Container:

```
use Utopia\DI\Container;
use Utopia\DI\Dependency;

$container = new Container();

$timing = new Dependency();
$timing
    ->setName('timing')
    ->setCallback(fn () => \microtime(true));

$container->add($timing);
```

Inject resource into endpoint action:

```
Http::get('/')
    ->inject('timing')
    ->inject('response')
    ->action(function(float $timing, Response $response) {
        $response->send('Request Unix timestamp: ' . \strval($timing));
    });
```

Inject resource into a hook:

```
Http::shutdown()
    ->inject('timing')
    ->action(function(float $timing) {
        $difference = \microtime(true) - $timing;
        \var_dump("Request took: " . $difference . " seconds");
    });
```

In advanced scenarios, resources can also be injected into other resources or endpoint parameters.

Resources 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.

To learn more about architecture and features for this library, check out more in-depth [Getting started guide](/docs/Getting-Starting-Guide.md).

System Requirements
-------------------

[](#system-requirements)

Utopia Framework requires PHP 8.1 or later. We recommend using the latest PHP version whenever possible.

More from Utopia
----------------

[](#more-from-utopia)

Our ecosystem supports other thin PHP projects aiming to extend the core PHP Utopia HTTP.

Each project is focused on solving a single, very simple problem and you can use composer to include any of them in your next project.

You can find all libraries in [GitHub Utopia organization](https://github.com/utopia-php).

Contributing
------------

[](#contributing)

All 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.

Fork the project, create a feature branch, and send us a pull request.

You can refer to the [Contributing Guide](https://github.com/utopia-php/http/blob/master/CONTRIBUTING.md) for more info.

For security issues, please email  instead of posting a public issue in GitHub.

Copyright and license
---------------------

[](#copyright-and-license)

The MIT License (MIT)

###  Health Score

67

↑

FairBetter than 100% of packages

Maintenance98

Actively maintained with recent releases

Popularity41

Moderate usage in the ecosystem

Community29

Small or concentrated contributor base

Maturity87

Battle-tested with a long release history

 Bus Factor3

3 contributors hold 50%+ of commits

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~14 days

Recently: every ~5 days

Total

175

Last Release

1d ago

Major Versions

0.33.28 → 1.0.32025-10-16

0.33.31 → 1.2.02025-10-21

0.34.12 → 1.2.12025-12-31

0.34.13 → 1.2.32026-02-19

0.34.14 → 1.2.42026-03-03

PHP version history (7 changes)v0.1.0PHP &gt;=7.0.0

0.9.2PHP &gt;=7.3.0

0.19.2PHP &gt;=8.0.0

0.28.2PHP &gt;=8.0

0.33.12PHP &gt;=8.1

0.33.34PHP &gt;=8.3

0.34.15PHP &gt;=8.2

### Community

Maintainers

![](https://www.gravatar.com/avatar/023f08a9df59f81cc4a04b1cebd20f45ede5db53ef2f9e9ad3d75f4c69be66b8?d=identicon)[eldadfux](/maintainers/eldadfux)

---

Top Contributors

[![eldadfux](https://avatars.githubusercontent.com/u/1297371?v=4)](https://github.com/eldadfux "eldadfux (248 commits)")[![lohanidamodar](https://avatars.githubusercontent.com/u/6360216?v=4)](https://github.com/lohanidamodar "lohanidamodar (190 commits)")[![Meldiron](https://avatars.githubusercontent.com/u/19310830?v=4)](https://github.com/Meldiron "Meldiron (136 commits)")[![TorstenDittmann](https://avatars.githubusercontent.com/u/1759475?v=4)](https://github.com/TorstenDittmann "TorstenDittmann (92 commits)")[![christyjacob4](https://avatars.githubusercontent.com/u/20852629?v=4)](https://github.com/christyjacob4 "christyjacob4 (63 commits)")[![kodumbeats](https://avatars.githubusercontent.com/u/9708641?v=4)](https://github.com/kodumbeats "kodumbeats (38 commits)")[![loks0n](https://avatars.githubusercontent.com/u/22452787?v=4)](https://github.com/loks0n "loks0n (34 commits)")[![abnegate](https://avatars.githubusercontent.com/u/5857008?v=4)](https://github.com/abnegate "abnegate (28 commits)")[![byawitz](https://avatars.githubusercontent.com/u/316103?v=4)](https://github.com/byawitz "byawitz (22 commits)")[![vermakhushboo](https://avatars.githubusercontent.com/u/43381712?v=4)](https://github.com/vermakhushboo "vermakhushboo (15 commits)")[![aaryan2134](https://avatars.githubusercontent.com/u/22559451?v=4)](https://github.com/aaryan2134 "aaryan2134 (13 commits)")[![ChiragAgg5k](https://avatars.githubusercontent.com/u/110609663?v=4)](https://github.com/ChiragAgg5k "ChiragAgg5k (8 commits)")[![shimonewman](https://avatars.githubusercontent.com/u/23742426?v=4)](https://github.com/shimonewman "shimonewman (8 commits)")[![thinkverse](https://avatars.githubusercontent.com/u/2221746?v=4)](https://github.com/thinkverse "thinkverse (7 commits)")[![stnguyen90](https://avatars.githubusercontent.com/u/1477010?v=4)](https://github.com/stnguyen90 "stnguyen90 (7 commits)")[![basert](https://avatars.githubusercontent.com/u/1951610?v=4)](https://github.com/basert "basert (6 commits)")[![Aadeesh11](https://avatars.githubusercontent.com/u/66922161?v=4)](https://github.com/Aadeesh11 "Aadeesh11 (2 commits)")[![ebenezerdon](https://avatars.githubusercontent.com/u/43746609?v=4)](https://github.com/ebenezerdon "ebenezerdon (2 commits)")[![PineappleIOnic](https://avatars.githubusercontent.com/u/26739219?v=4)](https://github.com/PineappleIOnic "PineappleIOnic (2 commits)")[![Rutam21](https://avatars.githubusercontent.com/u/47860497?v=4)](https://github.com/Rutam21 "Rutam21 (2 commits)")

---

Tags

frameworkhacktoberfestmicro-frameworkphprouterhttpphpframeworkupf

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StyleLaravel Pint

Type Coverage Yes

### Embed Badge

![Health badge](/badges/utopia-php-http/health.svg)

```
[![Health](https://phpackages.com/badges/utopia-php-http/health.svg)](https://phpackages.com/packages/utopia-php-http)
```

###  Alternatives

[utopia-php/framework

A simple, light and advanced PHP HTTP framework

294589.7k8](/packages/utopia-php-framework)[utopia-php/domains

Utopia Domains library is simple and lite library for parsing web domains. This library is aiming to be as simple and easy to learn and use.

53578.2k8](/packages/utopia-php-domains)[utopia-php/storage

A simple Storage library to manage application storage

30225.9k3](/packages/utopia-php-storage)[utopia-php/queue

A powerful task queue.

11170.5k2](/packages/utopia-php-queue)[utopia-php/swoole

An extension for Utopia Framework to work with PHP Swoole as a PHP FPM alternative

18315.0k1](/packages/utopia-php-swoole)[utopia-php/cli

A simple CLI library to manage command line applications

41377.8k6](/packages/utopia-php-cli)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
