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

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

jdz/http
========

A PHP library to handle HTTP status HTTP statuses.

2.0.0(5mo ago)016MITPHPPHP ^8.1

Since Dec 13Pushed 5mo ago1 watchersCompare

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

READMEChangelog (3)Dependencies (1)Versions (5)Used By (0)

JDZ HTTP Status
===============

[](#jdz-http-status)

Some useful utilities for HTTP responses (codes).

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

[](#installation)

To install this library, use Composer:

```
composer require jdz/http
```

Versions
--------

[](#versions)

**V1**: Provides three separate enums: `HttpStatusCode`, `HttpStatusText`, and `HttpStatusAlias`.

**V2**: Added a single combined enum: `HttpStatus` with methods to get code, text, and alias.

**Both approaches are valid and produce the same results!**The three separate enums (`HttpStatusCode`, `HttpStatusText`, `HttpStatusAlias`) do exactly the same thing as `HttpStatus`, but `HttpStatus` combines them into a single, more convenient API with built-in `getText()` and `getAlias()` methods.

### Use HttpStatus when:

[](#use-httpstatus-when)

- You want a simple, all-in-one solution
- You need code, text, and alias together
- You prefer a cleaner API

```
$status = HttpStatus::HTTP_200;
echo $status->value;       // 200
echo $status->getText();   // OK
echo $status->getAlias();  // HTTP_OK
```

### Use Separate Enums when:

[](#use-separate-enums-when)

- You only need specific information (e.g., just codes)
- You want more granular control
- You're building a more complex system with specific requirements

```
$code = HttpStatusCode::HTTP_200;
$text = HttpStatusText::fromHttpStatusCode($code);
$alias = HttpStatusAlias::fromHttpStatusCode($code);

echo $code->value;   // 200
echo $text->value;   // OK
echo $alias->value;  // HTTP_OK
```

Usage
-----

[](#usage)

### HttpStatus

[](#httpstatus)

The HttpStatus enum provides numeric values for HTTP status codes \[[https://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml\](as](https://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml](as) registered by IANA).

```
