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

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

bayfrontmedia/php-http-response
===============================

Easily send HTTP responses.

v2.0.3(1y ago)61.8k↓100%14MITPHPPHP ^8.0

Since Aug 10Pushed 1y ago1 watchersCompare

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

READMEChangelog (10)DependenciesVersions (12)Used By (4)

PHP HTTP response
-----------------

[](#php-http-response)

Easily send HTTP responses.

- [License](#license)
- [Author](#author)
- [Requirements](#requirements)
- [Installation](#installation)
- [Usage](#usage)

License
-------

[](#license)

This project is open source and available under the [MIT License](LICENSE).

Author
------

[](#author)

[![Bayfront Media](https://camo.githubusercontent.com/0c0163913b2092e97dbf9684970adaf86f2f25871298d3d28b2dff4bf75b2915/68747470733a2f2f63646e312e6f6e62617966726f6e742e636f6d2f62666d2f6272616e642f62666d2d6c6f676f2e737667)](https://camo.githubusercontent.com/0c0163913b2092e97dbf9684970adaf86f2f25871298d3d28b2dff4bf75b2915/68747470733a2f2f63646e312e6f6e62617966726f6e742e636f6d2f62666d2f6272616e642f62666d2d6c6f676f2e737667)

- [Bayfront Media homepage](https://www.bayfrontmedia.com?utm_source=github&utm_medium=direct)
- [Bayfront Media GitHub](https://github.com/bayfrontmedia)

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

[](#requirements)

- PHP `^8.0` (Tested up to `8.4`)
- JSON PHP extension

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

[](#installation)

```
composer require bayfrontmedia/php-http-response

```

Usage
-----

[](#usage)

- [reset](#reset)
- [setStatusCode](#setstatuscode)
- [getStatusCode](#getstatuscode)
- [removeHeaders](#removeheaders)
- [setHeaders](#setheaders)
- [getHeaders](#getheaders)
- [setBody](#setbody)
- [getBody](#getbody)
- [send](#send)
- [sendJson](#sendjson)
- [redirect](#redirect)

---

### reset

[](#reset)

**Description:**

Resets all headers (including status code) and body.

**Parameters:**

- None

**Returns:**

- (self)

**Example:**

```
$response->reset();

```

---

### setStatusCode

[](#setstatuscode)

**Description:**

Sets status code to be sent with response.

**Parameters:**

- `$status` (int)

**Returns:**

- (self)

**Throws:**

- `Bayfront\HttpResponse\InvalidStatusCodeException`

**Example:**

```
use Bayfront\HttpResponse\InvalidStatusCodeException;
use Bayfront\HttpResponse\Response;

$response = new Response();

try {

    $response->setStatusCode(429);

} catch (InvalidStatusCodeException $e) {
    die($e->getMessage());
}

```

---

### getStatusCode

[](#getstatuscode)

**Description:**

Returns the status code and associated phrase to be sent with response.

**Parameters:**

- None

**Returns:**

- (array)

**Example:**

```
print_r($response->getStatusCode());

```

---

### removeHeaders

[](#removeheaders)

**Description:**

Sets header values to be removed with the response.

**Parameters:**

- `$headers` (array)

**Returns:**

- (self)

**Example:**

```
$response->removeHeaders([
    'X-Powered-By'
]);

```

---

### setHeaders

[](#setheaders)

**Description:**

Sets header values to be sent with the response.

**Parameters:**

- `$headers` (array)

**Returns:**

- (self)

**Example:**

```
$response->setHeaders([
    'X-Rate-Limit-Limit' => 100,
    'X-Rate-Limit-Remaining' => 99
]);

```

---

### getHeaders

[](#getheaders)

**Description:**

Returns array of headers to be sent with the response.

**Parameters:**

- None

**Returns:**

- (array)

**Example:**

```
print_r($response->getHeaders());

```

---

### setBody

[](#setbody)

**Description:**

Sets body to be sent with the response.

**Parameters:**

- `$body` (string)

**Returns:**

- (self)

**Example:**

```
$response->setBody('This is the response body.');

```

---

### getBody

[](#getbody)

**Description:**

Returns body to be sent with the response.

**Parameters:**

- None

**Returns:**

- (string)

**Example:**

```
echo $response->getBody();

```

---

### send

[](#send)

**Description:**

Sends response.

**Parameters:**

- None

**Returns:**

- (void)

**Example:**

```
$response->send();

```

---

### sendJson

[](#sendjson)

**Description:**

Sets Content-Type as `application/json`, and converts the given array to the JSON encoded body.

**Parameters:**

- `$array` (array)

**Returns:**

- (void)

**Example:**

```
$response->sendJson([
    'results' => [
        'user_id' => 5,
        'username' => 'some_username'
    ],
    'status' => 'OK'
]);

```

---

### redirect

[](#redirect)

**Description:**

Redirects to a given URL using a given status code.

**Parameters:**

- `$url` (string)
- `$status = 302` (int): HTTP status code to return

**Returns:**

- (void)

**Throws:**

- `Bayfront\HttpResponse\InvalidStatusCodeException`

**Example:**

```
use Bayfront\HttpResponse\InvalidStatusCodeException;
use Bayfront\HttpResponse\Response;

$response = new Response();

try {

    $response->redirect('https://www.google.com', 301);

} catch (InvalidStatusCodeException $e) {
    die($e->getMessage());
}

```

###  Health Score

39

—

LowBetter than 85% of packages

Maintenance42

Moderate activity, may be stable

Popularity23

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity66

Established project with proven stability

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

Recently: every ~176 days

Total

11

Last Release

498d ago

Major Versions

v1.4.0 → v2.0.02023-01-23

PHP version history (3 changes)1.0.0PHP &gt;=7.1.0

v1.4.0PHP ^7.1.0

v2.0.0PHP ^8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/5ad62c8d0e69358fd63b16fdaa71d5359231cd0cf660bbc3419071dc705c63a8?d=identicon)[bayfrontmedia](/maintainers/bayfrontmedia)

---

Top Contributors

[![robinsonjohn](https://avatars.githubusercontent.com/u/24327848?v=4)](https://github.com/robinsonjohn "robinsonjohn (18 commits)")

---

Tags

headerhttpmethodphpredirectresponseurlhttpresponseurlphpheadermethodredirect

### Embed Badge

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

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

PHPackages © 2026

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