PHPackages                             chevere/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. [HTTP &amp; Networking](/categories/http)
4. /
5. chevere/http

ActiveLibrary[HTTP &amp; Networking](/categories/http)

chevere/http
============

PSR-7/17/18 compatible PHP library for creating HTTP components for routing

0.7.1(5mo ago)16.4k↓33.3%[2 issues](https://github.com/chevere/http/issues)6Apache-2.0PHPPHP ^8.1CI failing

Since Jun 7Pushed 2mo agoCompare

[ Source](https://github.com/chevere/http)[ Packagist](https://packagist.org/packages/chevere/http)[ Docs](https://chevere.org)[ RSS](/packages/chevere-http/feed)WikiDiscussions 0.8 Synced 1mo ago

READMEChangelog (10)Dependencies (13)Versions (18)Used By (6)

Http
====

[](#http)

[![Chevere](chevere.svg)](chevere.svg)

[![Build](https://camo.githubusercontent.com/802f99a989cf7fc36e85a38d9158627ab83fe516cf6d3e5e381772e51bff47f0/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f636865766572652f687474702f746573742e796d6c3f6272616e63683d302e38267374796c653d666c61742d737175617265)](https://github.com/chevere/http/actions)[![Code size](https://camo.githubusercontent.com/eab67b6c427f7a61a1080dc7a6b60f863e801cb163e79759a6f6abbef1561698/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c616e6775616765732f636f64652d73697a652f636865766572652f687474703f7374796c653d666c61742d737175617265)](https://camo.githubusercontent.com/eab67b6c427f7a61a1080dc7a6b60f863e801cb163e79759a6f6abbef1561698/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c616e6775616765732f636f64652d73697a652f636865766572652f687474703f7374796c653d666c61742d737175617265)[![Apache-2.0](https://camo.githubusercontent.com/ded098f997d484d66d65ba7b464e707d97b95ce1402361ef141e884afd839257/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f636865766572652f687474703f7374796c653d666c61742d737175617265)](LICENSE)[![PHPStan](https://camo.githubusercontent.com/6016298b28550819030c76e9327f62501596a31fd76406695bae2f3d2a1f26a4/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048505374616e2d6c6576656c253230392d626c756576696f6c65743f7374796c653d666c61742d737175617265)](https://phpstan.org/)[![Mutation testing badge](https://camo.githubusercontent.com/9783d8dd17bb863676247898307a7b67606125ffc95915885b1b6ff61a8026c3/68747470733a2f2f696d672e736869656c64732e696f2f656e64706f696e743f7374796c653d666c61742d7371756172652675726c3d687474707325334125324625324662616467652d6170692e737472796b65722d6d757461746f722e696f2532466769746875622e636f6d2532466368657665726525324668747470253246302e38)](https://dashboard.stryker-mutator.io/reports/github.com/chevere/http/0.8)

[![Quality Gate Status](https://camo.githubusercontent.com/554ba7c8a526fef780253c7b2ee9456e2ef08842145b41b3169dc6be7cac7a1f/68747470733a2f2f736f6e6172636c6f75642e696f2f6170692f70726f6a6563745f6261646765732f6d6561737572653f70726f6a6563743d636865766572655f68747470266d65747269633d616c6572745f737461747573)](https://sonarcloud.io/dashboard?id=chevere_http)[![Maintainability Rating](https://camo.githubusercontent.com/0816721f542ea5324ec3f303af87dee4b4a3cc2b45cde1c3b54d6059d7c93d42/68747470733a2f2f736f6e6172636c6f75642e696f2f6170692f70726f6a6563745f6261646765732f6d6561737572653f70726f6a6563743d636865766572655f68747470266d65747269633d7371616c655f726174696e67)](https://sonarcloud.io/dashboard?id=chevere_http)[![Reliability Rating](https://camo.githubusercontent.com/939a4309f4886f063521c78d6801ac0ab3f707aeb3235cc28821fd2abc7e4de6/68747470733a2f2f736f6e6172636c6f75642e696f2f6170692f70726f6a6563745f6261646765732f6d6561737572653f70726f6a6563743d636865766572655f68747470266d65747269633d72656c696162696c6974795f726174696e67)](https://sonarcloud.io/dashboard?id=chevere_http)[![Security Rating](https://camo.githubusercontent.com/81abfc03ef06e17aaa66287fd1c2ffc7f34b23471d93392dcbd5283e545468b1/68747470733a2f2f736f6e6172636c6f75642e696f2f6170692f70726f6a6563745f6261646765732f6d6561737572653f70726f6a6563743d636865766572655f68747470266d65747269633d73656375726974795f726174696e67)](https://sonarcloud.io/dashboard?id=chevere_http)[![Coverage](https://camo.githubusercontent.com/ea07291c44897ca4cfb953ab18203c486d991a6848a6e5ee9416ba4dcaf3d2d4/68747470733a2f2f736f6e6172636c6f75642e696f2f6170692f70726f6a6563745f6261646765732f6d6561737572653f70726f6a6563743d636865766572655f68747470266d65747269633d636f766572616765)](https://sonarcloud.io/dashboard?id=chevere_http)[![Technical Debt](https://camo.githubusercontent.com/8f71b7874b0197cd6ce732703b3cb519455a58442aedcc29e05865f0c5e19029/68747470733a2f2f736f6e6172636c6f75642e696f2f6170692f70726f6a6563745f6261646765732f6d6561737572653f70726f6a6563743d636865766572655f68747470266d65747269633d7371616c655f696e646578)](https://sonarcloud.io/dashboard?id=chevere_http)[![CodeFactor](https://camo.githubusercontent.com/14580c3bf6f3f1533f5004f53cd3905d2849dc1ac2ba62c01a57b41a363673a7/68747470733a2f2f7777772e636f6465666163746f722e696f2f7265706f7369746f72792f6769746875622f636865766572652f687474702f6261646765)](https://www.codefactor.io/repository/github/chevere/http)[![Codacy Badge](https://camo.githubusercontent.com/6af8d8fc85aaef81a30bf0b9213e27aeb51c331beb1e96a2d402ca95847bb4a6/68747470733a2f2f6170702e636f646163792e636f6d2f70726f6a6563742f62616467652f47726164652f6239353637353466386666303461616139636132346136653463633231363631)](https://app.codacy.com/gh/chevere/http/dashboard)

Summary
-------

[](#summary)

Http is a library for creating HTTP components (Controller, Middleware, Header, Status) for [chevere/router](https://chevere.org/packages/router). It is compatible with the following [PHP-FIG](https://www.php-fig.org) PSR:

- PSR-7: HTTP message interfaces
- PSR-17: HTTP Factories
- PSR-18: HTTP Client

Read [Chevere Http](https://rodolfoberrios.com/2023/06/13/http/) at Rodolfo's blog for a compressive introduction to this package.

Installing
----------

[](#installing)

Http is available through [Packagist](https://packagist.org/packages/chevere/http) and the repository source is at [chevere/http](https://github.com/chevere/http).

```
composer require chevere/http
```

Controller
----------

[](#controller)

The Controller in Http is a special Controller meant to be used in the context of HTTP requests. It extends [Action](https://chevere.org/packages/action) by adding request [parameters](https://chevere.org/packages/parameter) (query string, body, files) and attributes for statuses and headers.

```
use Chevere\Http\Controller;

class UsersPostController extends Controller
{
    // ...
}
```

### Accept Headers

[](#accept-headers)

Define accepted parameters for headers using the `acceptHeaders` method.

```
use Chevere\Parameter\Interfaces\ArrayStringParameterInterface;
use function Chevere\Parameter\arrayString;
use function Chevere\Parameter\parameters;
use function Chevere\Parameter\string;

public static function acceptHeaders(): ArrayStringParameterInterface
{
    return arrayString(
        ...['Webhook-Id' => string()],
    );
}
```

### Accept Query

[](#accept-query)

Define accepted parameters for query string using the `acceptQuery` method.

```
use Chevere\Parameter\Interfaces\ArrayStringParameterInterface;
use function Chevere\Parameter\arrayString;
use function Chevere\Parameter\parameters;
use function Chevere\Parameter\string;

public static function acceptQuery(): ArrayStringParameterInterface
{
    return arrayString(
        foo: string('/^[a-z]+$/'),
    );
}
```

### Accept Body

[](#accept-body)

Define accepted parameters for body using the `acceptBody` method.

```
use Chevere\Parameter\Interfaces\ArrayParameterInterface;
use function Chevere\Parameter\arrayp;
use function Chevere\Parameter\parameters;
use function Chevere\Parameter\string;

public static function acceptBody(): ArrayParameterInterface
{
    return arrayp(
        bar: string('/^[1-9]+$/'),
    );
}
```

### Accept Files

[](#accept-files)

Define accepted parameters for FILES using the `acceptFiles` method.

```
use Chevere\Parameter\Interfaces\ArrayParameterInterface;
use function Chevere\Parameter\arrayp;
use function Chevere\Parameter\file;

public static function acceptFiles(): ArrayParameterInterface
{
    return arrayp(
        myFile: file(),
    );
}
```

### With Server Request

[](#with-server-request)

Use method `withServerRequest` to inject a [PSR-7 ServerRequest](https://www.php-fig.org/psr/psr-7/#31-psrhttpmessageserverrequestinterface) instance. This will assert the request against the defined `accept*` methods.

```
use Psr\Http\Message\ServerRequestInterface;

$controller = $controller
    ->withServerRequest($request);
```

### Headers

[](#headers)

Use method `headers` to read headers parameters.

```
$headers = $controller->headers();
$header = $headers->required('Webhook-Id');
```

### Query

[](#query)

Use method `query` to read query parameters.

```
$query = $controller->query();
$foo = $query->required('foo');
```

### Body

[](#body)

Use method `bodyParsed` to read the body parameters parsed.

```
$parsed = $controller->bodyParsed();
$bar = $parsed->required('bar')->int();
```

Use method `bodyStream` to return the body stream.

```
$stream = $controller->bodyStream();
```

Use method `body` to return the body casted.

```
$cast = $controller->body();
```

### Files

[](#files)

Use method `files` to read the files parameters.

```
$files = $controller->files();
```

Middleware
----------

[](#middleware)

Define [PSR Middleware](https://www.php-fig.org/psr/psr-15/) collections using `middlewares` function.

```
use function Chevere\Http\middlewares;

$middlewares = middlewares(
    MiddlewareOne::class,
    MiddlewareTwo::class
);
```

Middleware priority goes from top to bottom, first in first out (FIFO).

### Middleware with Arguments

[](#middleware-with-arguments)

Use `MiddlewareNameWithArgumentsTrait` to define Middleware with arguments:

```
use Chevere\Http\Interfaces\MiddlewareNameInterface;
use Chevere\Http\Traits\MiddlewareNameWithArgumentsTrait;
use Nyholm\Psr7\Factory\Psr17Factory;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\MiddlewareInterface;

class AllowListMiddleware implements MiddlewareInterface
{
    use MiddlewareNameWithArgumentsTrait;

    private string $allowList;

    public function setUp(string $allowList): void
    {
        $this->allowList = $allowList;
    }

    public static function with(string $allowList): MiddlewareNameInterface
    {
        return static::middlewareName(...get_defined_vars());
    }

    public function process(
        ServerRequestInterface $request,
        RequestHandlerInterface $handler,
    ): ResponseInterface {
        if ($this->allowList === '') {
            return $handler->handle($request);
        }
        $remoteAddress = $request->getServerParams()['REMOTE_ADDR'] ?? '';
        if ($remoteAddress === '') {
            return (new Psr17Factory())
                ->createResponse(
                    400,
                    'Unable to determine client IP address'
                );
        }
        if (! isIpAllowed($remoteAddress, $this->allowList)) {
            return (new Psr17Factory())
                ->createResponse(
                    403,
                    'Access denied from your IP address'
                );
        }

        return $handler->handle($request);
    }
}
```

This allows to pass MiddlewareName with constructor arguments (as in when defining [routes](https://chevere.org/packages/router)):

```
$middlewareName = AllowListMiddleware::with('192.168.1.1');
```

Attributes
----------

[](#attributes)

Use [attributes](https://www.php.net/manual/en/language.attributes.overview.php) to add context for [Controller](#controller) and [Middleware](#middleware).

### Request

[](#request)

Request metadata can be defined using the `Request` attribute. It supports to define multiple Header arguments.

```
use Chevere\Http\Attributes\Request;
use Chevere\Http\Header;
use Chevere\Http\Controller;

#[Request(
    new Header('Accept', 'application/json'),
    new Header('Connection', 'keep-alive')
)]
class ResourceGetController extends Controller
```

Use function `getRequest` to read the `Request` attribute.

```
use function Chevere\Http\getRequest;

getRequest(ResourceGetController::class);
```

### Response

[](#response)

Response metadata can be defined using the `Response` attribute. It supports to define Status and multiple Header arguments.

```
use Chevere\Http\Attributes\Response;
use Chevere\Http\Header;
use Chevere\Http\Controller;

#[Response(
    new Status(200),
    new Header('Content-Disposition', 'attachment'),
    new Header('Content-Type', 'application/json')
)]
class ResourceGetController extends Controller
```

Use function `getResponse` to read the `Response` attribute.

```
use function Chevere\Http\getResponse;

getResponse(ResourceGetController::class);
```

Documentation
-------------

[](#documentation)

Documentation is available at [chevere.org](https://chevere.org/packages/http).

License
-------

[](#license)

Copyright [Rodolfo Berrios A.](https://rodolfoberrios.com/)

Chevere is licensed under the Apache License, Version 2.0. See [LICENSE](LICENSE) for the full license text.

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

###  Health Score

39

—

LowBetter than 86% of packages

Maintenance59

Moderate activity, may be stable

Popularity24

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity51

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

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 ~59 days

Recently: every ~48 days

Total

18

Last Release

66d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/a87fbbcb1518fe64878bc53dedd9f61b81243cbb21b73c26f5e299d501375984?d=identicon)[rodolfo](/maintainers/rodolfo)

---

Top Contributors

[![rodber](https://avatars.githubusercontent.com/u/20590102?v=4)](https://github.com/rodber "rodber (179 commits)")

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StyleECS

Type Coverage Yes

### Embed Badge

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

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

###  Alternatives

[cakephp/cakephp

The CakePHP framework

8.8k18.5M1.6k](/packages/cakephp-cakephp)[thecodingmachine/graphqlite

Write your GraphQL queries in simple to write controllers (using webonyx/graphql-php).

5723.1M30](/packages/thecodingmachine-graphqlite)[neos/flow

Flow Application Framework

862.0M451](/packages/neos-flow)[neos/flow-development-collection

Flow packages in a joined repository for pull requests.

144179.3k3](/packages/neos-flow-development-collection)[mezzio/mezzio-authentication-oauth2

OAuth2 (server) authentication middleware for Mezzio and PSR-7 applications.

28483.0k2](/packages/mezzio-mezzio-authentication-oauth2)[windwalker/framework

The next generation PHP framework.

25639.1k1](/packages/windwalker-framework)

PHPackages © 2026

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