PHPackages                             josantonius/http-status-code - 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. josantonius/http-status-code

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

josantonius/http-status-code
============================

PHP library to get HTTP status code messages and definitions.

v2.0.4(3y ago)92.9k↓50%21MITPHPPHP ^8.0

Since Dec 19Pushed 3y ago1 watchersCompare

[ Source](https://github.com/josantonius/php-http-status-code)[ Packagist](https://packagist.org/packages/josantonius/http-status-code)[ GitHub Sponsors](https://github.com/Josantonius)[ RSS](/packages/josantonius-http-status-code/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (3)Versions (14)Used By (1)

PHP HTTP Status Code library
============================

[](#php-http-status-code-library)

[![Latest Stable Version](https://camo.githubusercontent.com/5fb2c446b64c37eb9b902f74bd5036de15e4d89802d52df79f22b5e5cdc1f948/68747470733a2f2f706f7365722e707567782e6f72672f6a6f73616e746f6e6975732f687474702d7374617475732d636f64652f762f737461626c65)](https://packagist.org/packages/josantonius/http-status-code)[![License](https://camo.githubusercontent.com/0210098d82d779927009bd6ce5f564b2a9349065401ddd35364c2ac546829e04/68747470733a2f2f706f7365722e707567782e6f72672f6a6f73616e746f6e6975732f687474702d7374617475732d636f64652f6c6963656e7365)](LICENSE)[![Total Downloads](https://camo.githubusercontent.com/b981ddc77fe1aaaed19de3c4ed571d2557ed36e1a8155839feb29e2821a06e4d/68747470733a2f2f706f7365722e707567782e6f72672f6a6f73616e746f6e6975732f687474702d7374617475732d636f64652f646f776e6c6f616473)](https://packagist.org/packages/josantonius/http-status-code)[![CI](https://github.com/josantonius/php-http-status-code/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/josantonius/php-http-status-code/actions/workflows/ci.yml)[![CodeCov](https://camo.githubusercontent.com/2979ca3990892e825ebde9ebc42b5242a3a3b625185e27764b40584dd6781a06/68747470733a2f2f636f6465636f762e696f2f67682f6a6f73616e746f6e6975732f7068702d687474702d7374617475732d636f64652f6272616e63682f6d61696e2f67726170682f62616467652e737667)](https://codecov.io/gh/josantonius/php-http-status-code)[![PSR1](https://camo.githubusercontent.com/b502a899c9aec217e98971160f816f87346be272cf1a25cfa4793f2ee724bfc8/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5053522d312d6635373034362e737667)](https://www.php-fig.org/psr/psr-1/)[![PSR4](https://camo.githubusercontent.com/d1c090de87e968254a6658528f3bfe9c9dad422d6047fd1323dc211560182c01/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5053522d342d3962353962362e737667)](https://www.php-fig.org/psr/psr-4/)[![PSR12](https://camo.githubusercontent.com/19c529c6dc0656dcc2a16c1a84af450b7bd0dc7b0571b8f17e4fc9f2414f8821/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5053522d31322d3161626339632e737667)](https://www.php-fig.org/psr/psr-12/)

**Translations**: [Español](.github/lang/es-ES/README.md)

PHP library to get HTTP status code messages and definitions.

---

- [Requirements](#requirements)
- [Installation](#installation)
- [Available Classes](#available-classes)
    - [HttpStatusCode Class](#httpstatuscode-class)
- [Exceptions Used](#exceptions-used)
- [Usage](#usage)
- [List in JSON format](#list-in-json-format)
- [Tests](#tests)
- [TODO](#todo)
- [Changelog](#changelog)
- [Contribution](#contribution)
- [Sponsor](#sponsor)
- [License](#license)

---

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

[](#requirements)

- Operating System: Linux | Windows.
- PHP versions: 8.0 | 8.1 | 8.2.

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

[](#installation)

The preferred way to install this extension is through [Composer](http://getcomposer.org/download/).

To install **PHP HTTP Status Code library**, simply:

```
composer require josantonius/http-status-code
```

The previous command will only install the necessary files, if you prefer to **download the entire source code** you can use:

```
composer require josantonius/http-status-code --prefer-source
```

You can also **clone the complete repository** with Git:

```
git clone https://github.com/josantonius/http-status-code.git
```

Available Classes
-----------------

[](#available-classes)

### HttpStatusCode Class

[](#httpstatuscode-class)

`Josantonius\HttpStatusCode\HttpStatusCode`

Create a new instance defining the language:

```
/**
 * @param string $language The language in which the data will be retrieved.
 *
 *                         Available languages: en (English)
 *                                              es (Spanish)
 *
 * @throws UnsupportedLanguageException if language is not supported.
 */
public function __construct(string $language = 'en');
```

Gets message of an HTTP status code:

```
public function getMessage(int $code): string|null;
```

Gets the messages of all HTTP status codes:

```
public function getMessages(): array;
```

Gets definition of an HTTP status code:

```
public function getDefinition(int $code): string|null;
```

Gets the definitions of all HTTP status codes:

```
public function getDefinitions(): array;
```

Gets messages and definitions of all HTTP status codes:

```
public function getAll(): array;
```

Exceptions Used
---------------

[](#exceptions-used)

```
use Josantonius\HttpStatusCode\UnsupportedLanguageException;
```

Usage
-----

[](#usage)

Example of use for this library:

### Create a new instance defining the language

[](#create-a-new-instance-defining-the-language)

```
use Josantonius\HttpStatusCode\HttpStatusCode;

$httpStatusCode = new HttpStatusCode();     // Gets the messages in English.
```

```
use Josantonius\HttpStatusCode\HttpStatusCode;

$httpStatusCode = new HttpStatusCode('es'); // Gets the messages in Spanish.
```

### Gets message of an HTTP status code

[](#gets-message-of-an-http-status-code)

```
use Josantonius\HttpStatusCode\HttpStatusCode;

$httpStatusCode = new HttpStatusCode();

$httpStatusCode->getMessage(404);
```

Returns:

```
'Not Found'
```

### Gets the messages of all HTTP status codes

[](#gets-the-messages-of-all-http-status-codes)

```
use Josantonius\HttpStatusCode\HttpStatusCode;

$httpStatusCode = new HttpStatusCode();

$httpStatusCode->getMessages();
```

Returns:

```
[
    100 => 'Continue',
    101 => 'Switching Protocols',
    102 => 'Processing',

    (...)
]
```

### Gets definition of an HTTP status code

[](#gets-definition-of-an-http-status-code)

```
use Josantonius\HttpStatusCode\HttpStatusCode;

$httpStatusCode = new HttpStatusCode();

$httpStatusCode->getDefinition(404);
```

Returns:

```
'The requested resource could not be found but (...)'
```

### Gets the definitions of all HTTP status codes

[](#gets-the-definitions-of-all-http-status-codes)

```
use Josantonius\HttpStatusCode\HttpStatusCode;

$httpStatusCode = new HttpStatusCode();

$httpStatusCode->getDefinitions();
```

Returns:

```
[
    100 => 'The server has received the request (...)',
    101 => 'The requester has asked the server (...)',
    102 => 'A WebDAV request may contain many (...)',

    (...)
]
```

### Gets messages and definitions of all HTTP status codes

[](#gets-messages-and-definitions-of-all-http-status-codes)

```
use Josantonius\HttpStatusCode\HttpStatusCode;

$httpStatusCode = new HttpStatusCode();

$httpStatusCode->getAll();
```

```
[
    100 => [
        'message'    => 'Continue',
        'definition' => 'The server has received the request (...)',
    ],
    101 => [
        'message'    => 'Switching Protocols',
        'definition' => 'The requester has asked the server (...)',
    ],
    102 => [
        'message'    => 'Processing',
        'definition' => 'A WebDAV request may contain many (...)',
    ],

    (...)
]
```

List in JSON format
-------------------

[](#list-in-json-format)

Tests
-----

[](#tests)

To run [tests](tests) you just need [composer](http://getcomposer.org/download/)and to execute the following:

```
git clone https://github.com/josantonius/php-http-status-code.git
```

```
cd php-http-status-code
```

```
composer install
```

Run unit tests with [PHPUnit](https://phpunit.de/):

```
composer phpunit
```

Run code standard tests with [PHPCS](https://github.com/squizlabs/PHP_CodeSniffer):

```
composer phpcs
```

Run [PHP Mess Detector](https://phpmd.org/) tests to detect inconsistencies in code style:

```
composer phpmd
```

Run all previous tests:

```
composer tests
```

TODO
----

[](#todo)

- Add new feature
- Improve tests
- Improve documentation
- Improve English translation in the README file
- Refactor code for disabled code style rules (see phpmd.xml and phpcs.xml)

Changelog
---------

[](#changelog)

Detailed changes for each release are documented in the [release notes](https://github.com/josantonius/php-http-status-code/releases).

Contribution
------------

[](#contribution)

Please make sure to read the [Contributing Guide](.github/CONTRIBUTING.md), before making a pull request, start a discussion or report a issue.

Thanks to all [contributors](https://github.com/josantonius/php-http-status-code/graphs/contributors)! ❤️

Sponsor
-------

[](#sponsor)

If this project helps you to reduce your development time, [you can sponsor me](https://github.com/josantonius#sponsor) to support my open source work 😊

License
-------

[](#license)

This repository is licensed under the [MIT License](LICENSE).

Copyright © 2016-present, [Josantonius](https://github.com/josantonius#contact)

###  Health Score

38

—

LowBetter than 85% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity28

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity75

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

Recently: every ~15 days

Total

12

Last Release

1327d ago

Major Versions

1.1.6 → v2.0.02022-07-31

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

1.1.1PHP ^5.6 || ^7.0

v2.0.0PHP ^8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/4b221283501ec8a9cbaefaf27821a91ae8ddd33bddf1fccc6c6815b7ad216ff1?d=identicon)[Josantonius](/maintainers/Josantonius)

---

Top Contributors

[![josantonius](https://avatars.githubusercontent.com/u/18104336?v=4)](https://github.com/josantonius "josantonius (48 commits)")

---

Tags

composerhttp-status-codehttp-status-codesphphttpphphttp-status-code

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/josantonius-http-status-code/health.svg)

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

###  Alternatives

[hannesvdvreken/guzzle-debugbar

A Guzzle middleware that logs requests to debugbar's timeline

76410.4k1](/packages/hannesvdvreken-guzzle-debugbar)[swoole-bundle/swoole-bundle

Open/Swoole Symfony Bundle

6650.4k](/packages/swoole-bundle-swoole-bundle)[ph-7/just-http-status-codes

Just all HTTP status codes

1447.7k4](/packages/ph-7-just-http-status-codes)

PHPackages © 2026

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