PHPackages                             componenta/http-responder - 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. componenta/http-responder

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

componenta/http-responder
=========================

HTTP response builder for Componenta

v1.0.0(1mo ago)084MITPHPPHP ^8.4

Since Jun 16Pushed 1mo agoCompare

[ Source](https://github.com/componenta/http-responder)[ Packagist](https://packagist.org/packages/componenta/http-responder)[ RSS](/packages/componenta-http-responder/feed)WikiDiscussions main Synced 1w ago

READMEChangelog (1)Dependencies (5)Versions (2)Used By (4)

Componenta HTTP Responder
=========================

[](#componenta-http-responder)

Response builder for PSR-7 HTTP responses. The package centralizes common response creation: JSON, text, HTML, redirects, downloads, inline files, error responses, and cache headers.

Use this package in controllers, route handlers, and middleware that need to create responses without depending on a concrete PSR-7 implementation.

Boundary
--------

[](#boundary)

This package only builds PSR-7 responses. It does not emit responses, does not create server requests, and does not choose a PSR-7 implementation. Use `componenta/http-emitter` to send responses and one of the `componenta/http-psr-*` packages to register PSR-17 factories.

Installation
------------

[](#installation)

```
composer require componenta/http-responder
```

The package declares `Componenta\Http\ResponderConfigProvider` in `extra.componenta.config-providers`. When `componenta/composer-plugin` is installed, the provider is added to the generated provider list automatically.

Register one PSR-17 implementation package, for example `componenta/http-psr-nyholm`, so the container has response and stream factories.

Configuration
-------------

[](#configuration)

`ResponderConfigProvider` registers `Responder` from:

DependencyPurpose`ResponseFactoryInterface`Creates PSR-7 responses.`StreamFactoryInterface`Creates body streams.The provider also includes the mime type detector provider for file responses.

Main API
--------

[](#main-api)

`Responder` is the consumer-facing service. It can either infer a response from arbitrary content or create a specific response type explicitly.

```
use Componenta\Http\Responder;

/** @var Responder $responder */

$json = $responder->json(['status' => 'ok']);
$redirect = $responder->seeOther('/dashboard');
$file = $responder->downloadFile('/tmp/report.pdf');
```

### Content responses

[](#content-responses)

MethodPurpose`respond(?int $code = null, mixed $content = null, ?string $contentType = null)`Builds a response from `null`, `ResponseInterface`, `StreamInterface`, `string`, `array`, `JsonSerializable`, `Arrayable`, `Stringable`, or a stream resource.`empty(int $status = 204)`Creates an empty response.`text(string $content, int $status = 200)`Creates a `text/plain; charset=utf-8` response.`html(string $content, int $status = 200)`Creates a `text/html; charset=utf-8` response.`xml(string $content, int $status = 200)`Creates an `application/xml; charset=utf-8` response.`json(mixed $data, int $status = 200, int $flags = ...)`JSON-encodes data with `JSON_THROW_ON_ERROR`, `JSON_UNESCAPED_UNICODE`, and `JSON_UNESCAPED_SLASHES` by default.`jsonp(mixed $data, string $callback, int $status = 200)`Creates a JavaScript callback response after validating the callback name.When `respond()` receives status `204` or `304`, it returns an empty response even if content is supplied.

### Redirects

[](#redirects)

MethodStatus`redirect(string $url, int $status = 302)`Custom redirect status.`movedPermanently(string $url)``301``found(string $url)``302``seeOther(string $url)``303``temporaryRedirect(string $url)``307``permanentRedirect(string $url)``308``back(?string $referer, string $fallback = '/')``302` to the referrer or fallback URL.Redirect URLs are trimmed and rejected when empty or when they contain control characters.

### Files

[](#files)

`download()` and `inline()` accept a `StreamInterface`, stream resource, or string content. `downloadFile()` and `inlineFile()` read from an absolute filesystem path and auto-detect the content type from the stream when possible.

```
$response = $responder->inlineFile('/srv/files/manual.pdf');
$nginx = $responder->xAccelRedirect('/internal/manual.pdf', 'manual.pdf');
```

MethodPurpose`download()` / `downloadFile()`Builds `Content-Disposition: attachment` responses.`inline()` / `inlineFile()`Builds `Content-Disposition: inline` responses.`file()` / `fileFromPath()`Lower-level file response helpers with an explicit disposition.`xAccelRedirect()`Header-only response for nginx internal file serving.`xSendfile()`Header-only response for Apache `mod_xsendfile`.### Error and conditional responses

[](#error-and-conditional-responses)

Convenience methods are available for common HTTP statuses: `badRequest()`, `unauthorized()`, `forbidden()`, `notFound()`, `methodNotAllowed()`, `conflict()`, `gone()`, `unprocessableEntity()`, `tooManyRequests()`, `serverError()`, `notImplemented()`, `serviceUnavailable()`, `notModified()`, `preconditionFailed()`, and `rangeNotSatisfiable()`.

`unauthorized()` can add `WWW-Authenticate`; `tooManyRequests()` and `serviceUnavailable()` can add `Retry-After`.

### Cache headers

[](#cache-headers)

Use `withCache()`, `withNoCache()`, `withEtag()`, and `withLastModified()` to add cache-related headers to an existing response. The methods return a modified PSR-7 response and do not mutate the original instance.

Errors
------

[](#errors)

The responder throws `InvalidArgumentException` when it receives unsupported content, invalid status codes, invalid redirect or header values, unreadable files, invalid filenames, invalid cache values, or invalid JSONP callback names.

###  Health Score

42

—

FairBetter than 88% of packages

Maintenance91

Actively maintained with recent releases

Popularity7

Limited adoption so far

Community11

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

Unknown

Total

1

Last Release

43d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/20490712?v=4)[Andrey Shelamkoff](/maintainers/Shelamkoff)[@Shelamkoff](https://github.com/Shelamkoff)

---

Top Contributors

[![Shelamkoff](https://avatars.githubusercontent.com/u/20490712?v=4)](https://github.com/Shelamkoff "Shelamkoff (1 commits)")

### Embed Badge

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

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

###  Alternatives

[symfony/symfony

The Symfony PHP framework

31.4k87.2M2.2k](/packages/symfony-symfony)[guzzlehttp/psr7

PSR-7 message implementation that also provides common utility methods

7.9k1.1B4.1k](/packages/guzzlehttp-psr7)[tempest/framework

The PHP framework that gets out of your way.

2.2k34.4k17](/packages/tempest-framework)[moonshine/moonshine

Laravel administration panel

1.3k253.1k86](/packages/moonshine-moonshine)[sunrise/http-router

A powerful solution as the foundation of your project.

17451.8k11](/packages/sunrise-http-router)[api-platform/state

API Platform state interfaces

294.9M137](/packages/api-platform-state)

PHPackages © 2026

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