PHPackages                             fastpress/response - 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. fastpress/response

ActiveLibrary[Framework](/categories/framework)

fastpress/response
==================

An efficient and flexible HTTP response handling library for PHP, designed to integrate seamlessly with the Fastpress framework. It offers easy-to-use methods for managing HTTP responses, headers, and status codes.

0.1.2(1y ago)0621MITPHPPHP ^7.4 || ^8.0

Since Feb 13Pushed 1y ago1 watchersCompare

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

READMEChangelogDependencies (3)Versions (4)Used By (1)

Fastpress\\Http\\Response
=========================

[](#fastpresshttpresponse)

A part of the Fastpress framework, **Fastpress\\Http\\Response** is a PHP class designed for handling HTTP responses efficiently and effectively. It offers a comprehensive set of features for managing response codes, headers, body content, and more, making it an indispensable tool for any PHP web application.

Features
--------

[](#features)

- **Response Code Management**: Easily set HTTP response codes and corresponding texts.
- **Response Body Handling**: Define and manage the body content of responses.
- **Headers Management**: Add and manipulate response headers.
- **Redirection Support**: Simple methods to redirect users to different URLs.
- **Caching Controls**: Methods to control and disable browser caching.
- **Protocol Specification**: Customize the HTTP protocol version.
- **Content Rendering**: Render the response content and headers efficiently.
- **Page Refresh**: Facilitate immediate page refreshes.

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

[](#installation)

Use Composer to integrate Fastpress\\Http\\Response into your project:

```
composer require fastpress/response
```

Requirements
------------

[](#requirements)

- PHP 7.4 or higher.

Usage
-----

[](#usage)

**Setting Response Code and Text**

```
use Fastpress\Http\Response;

$response = new Response();
$response->setResponse(200, 'OK');
```

Methods
-------

[](#methods)

### `setContent(mixed $content): self`

[](#setcontentmixed-content-self)

Sets the content of the response.

**Parameters:**

- `$content`: The content to send in the response.

**Returns:**

- The `Response` instance.

### `setContentType(string $contentType, ?string $charset = null): self`

[](#setcontenttypestring-contenttype-string-charset--null-self)

Sets the content type and optional charset of the response.

**Parameters:**

- `$contentType`: The content type (e.g., 'text/html', 'application/json').
- `$charset`: The charset (e.g., 'UTF-8').

**Returns:**

- The `Response` instance.

### `setStatusCode(int $code): self`

[](#setstatuscodeint-code-self)

Sets the HTTP status code of the response.

**Parameters:**

- `$code`: The HTTP status code (e.g., 200, 404, 500).

**Returns:**

- The `Response` instance.

### `header(string $name, string $value): self`

[](#headerstring-name-string-value-self)

Adds a header to the response.

**Parameters:**

- `$name`: The header name.
- `$value`: The header value.

**Returns:**

- The `Response` instance.

### `json(mixed $data, int $status = 200): self`

[](#jsonmixed-data-int-status--200-self)

Sends a JSON response.

**Parameters:**

- `$data`: The data to encode as JSON.
- `$status`: The HTTP status code.

**Returns:**

- The `Response` instance.

### `download(string $filepath, ?string $filename = null): void`

[](#downloadstring-filepath-string-filename--null-void)

Triggers a file download.

**Parameters:**

- `$filepath`: The path to the file.
- `$filename`: The filename to suggest to the browser.

**Returns:**

- `void`

### `redirect(string $url, int $code = 302): void`

[](#redirectstring-url-int-code--302-void)

Redirects to a given URL.

**Parameters:**

- `$url`: The URL to redirect to.
- `$code`: The HTTP status code (301, 302, etc.).

**Returns:**

- `void`

### `back(?string $fallback = '/'): void`

[](#backstring-fallback---void)

Redirects to the referring URL or a fallback URL.

**Parameters:**

- `$fallback`: The fallback URL if no referrer is available.

**Returns:**

- `void`

### `noCache(): self`

[](#nocache-self)

Adds headers to prevent caching of the response.

**Returns:**

- The `Response` instance.

### `withError(string $message, int $code = 400): self`

[](#witherrorstring-message-int-code--400-self)

Sends a JSON error response.

**Parameters:**

- `$message`: The error message.
- `$code`: The HTTP status code.

**Returns:**

- The `Response` instance.

### `withSuccess(mixed $data = null, string $message = 'Success'): self`

[](#withsuccessmixed-data--null-string-message--success-self)

Sends a JSON success response.

**Parameters:**

- `$data`: The data to include in the response.
- `$message`: The success message.

**Returns:**

- The `Response` instance.

### `send(): void`

[](#send-void)

Sends the HTTP response.

**Returns:**

- `void`

### `stream(callable $callback, int $bufferSize = 8192): void`

[](#streamcallable-callback-int-buffersize--8192-void)

Streams the response content.

**Parameters:**

- `$callback`: A callable that generates the response content in chunks.
- `$bufferSize`: The buffer size for each chunk.

**Returns:**

- `void`

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance42

Moderate activity, may be stable

Popularity8

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity38

Early-stage or recently created project

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

Total

3

Last Release

473d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/8224efc6c85f9ed635239195b886766f000c05d279ba93124dcc361c235efdf7?d=identicon)[samayo](/maintainers/samayo)

---

Top Contributors

[![samayo](https://avatars.githubusercontent.com/u/5304093?v=4)](https://github.com/samayo "samayo (2 commits)")

---

Tags

httpresponsephpframeworkhttp-responsefastpress

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP\_CodeSniffer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/fastpress-response/health.svg)

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

###  Alternatives

[utopia-php/framework

A simple, light and advanced PHP HTTP framework

295618.4k9](/packages/utopia-php-framework)[utopia-php/http

A simple, light and advanced PHP HTTP framework

2962.8k2](/packages/utopia-php-http)

PHPackages © 2026

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