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

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

alexanderpas/http-enum
======================

1.0.0(4y ago)81125.1k—8.2%53BSL-1.0PHPPHP ^8.1

Since Sep 20Pushed 1y ago2 watchersCompare

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

READMEChangelog (1)Dependencies (8)Versions (2)Used By (3)

HTTP Enums For PHP 8.1 and above
================================

[](#http-enums-for-php-81-and-above)

[![PHP Version Require](https://camo.githubusercontent.com/fe9f8e2d83a81e2ba937dbabeba760733fa32a763fbd16c2ec25de984d5a12e7/687474703a2f2f706f7365722e707567782e6f72672f616c6578616e6465727061732f687474702d656e756d2f726571756972652f706870)](https://packagist.org/packages/alexanderpas/http-enum)[![Latest Stable Version](https://camo.githubusercontent.com/bcb7ad2649506b1e097ace7be4f37b66943323284626cd99d22ef294c415fc6d/687474703a2f2f706f7365722e707567782e6f72672f616c6578616e6465727061732f687474702d656e756d2f76)](https://packagist.org/packages/alexanderpas/http-enum)[![Latest Unstable Version](https://camo.githubusercontent.com/4c513f9f5bd0009bb027172b09ea22a09c5e1760d5eafe3fbe6375d3a85cf047/687474703a2f2f706f7365722e707567782e6f72672f616c6578616e6465727061732f687474702d656e756d2f762f756e737461626c65)](https://packagist.org/packages/alexanderpas/http-enum)[![License](https://camo.githubusercontent.com/169b0b0814e291574f99aa49b474d8d69aa95a831f229ffc6773988dfd9215bf/687474703a2f2f706f7365722e707567782e6f72672f616c6578616e6465727061732f687474702d656e756d2f6c6963656e7365)](https://packagist.org/packages/alexanderpas/http-enum)

This package provides HTTP Methods, Status Codes and Reason Phrases as PHP 8.1+ enums

All [IANA registered HTTP Status codes](https://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml) and corresponding Reason Phrases as of the latest update on 2018-09-21 are supported.

This includes the HTTP Methods defined in [RFC 5789](https://www.iana.org/go/rfc5789) and [RFC 7231](https://www.iana.org/go/rfc7231), as well as all Status Codes and Reason Phrases as defined in [HTTP/1.1](https://en.wikipedia.org/wiki/HTTP/1.1) ([RFC 7231](https://www.iana.org/go/rfc7231), [RFC 7232](https://www.iana.org/go/rfc7232), [RFC 7233](https://www.iana.org/go/rfc7233), [RFC 7235](https://www.iana.org/go/rfc7235)) and [HTTP/2](https://en.wikipedia.org/wiki/HTTP/2) ([RFC 7540](https://www.iana.org/go/rfc7540)) as well as other RFC's defining HTTP status codes such as [WebDAV](https://en.wikipedia.org/wiki/WebDAV) ([RFC 2518](https://www.iana.org/go/rfc2518), [RFC 4918](https://www.iana.org/go/rfc4918), [RFC 5842](https://www.iana.org/go/rfc5842), [RFC 8144](https://www.iana.org/go/rfc8144)) and more ([RFC 8297](https://www.iana.org/go/rfc8297), [RFC 3229](https://www.iana.org/go/rfc3229), [RFC 7538](https://www.iana.org/go/rfc7538), [RFC 7694](https://www.iana.org/go/rfc7694), [RFC 6585](https://www.iana.org/go/rfc6585), [RFC 7725](https://www.iana.org/go/rfc7725), [RFC 2295](https://www.iana.org/go/rfc2295), [RFC 2774](https://www.iana.org/go/rfc2774))

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

[](#requirements)

- PHP 8.1 or above

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

[](#installation)

### Composer:

[](#composer)

```
composer require alexanderpas/http-enum

```

### Manually (Without Composer):

[](#manually-without-composer)

include the `src/Method.php` file in order to use the HTTP methods enum.

include both the `src/ReasonPhrase.php` file as well as the `src/StatusCode.php` file in order to use the HTTP Status Code enum or the HTTP Reason Phrase enum.

Available Enums and Enum methods
--------------------------------

[](#available-enums-and-enum-methods)

All available Enums live in the `\Alexanderpas\Common\HTTP` namespace.

- HTTP Methods are represented by the `\Alexanderpas\Common\HTTP\Method` enum.
- HTTP Status Codes are represented by the `\Alexanderpas\Common\HTTP\StatusCode` enum.
- HTTP Reason Phrases are represented by the `\Alexanderpas\Common\HTTP\ReasonPhrase` enum.

In addition to the Enum methods available by default on Backed Enums, the following Enum methods are available.

- `Method::fromName(string $name): Method` Gives back a HTTP method enum when provided with a valid HTTP method. (such as `'GET'` or `'POST'` or `'put'` or `'pAtcH'`)
- `StatusCode::fromInteger(int $integer): StatusCode` Gives back a HTTP Status Code enum when provided with a valid HTTP status code as integer. (such as `200` or `404`)
- `StatusCode::fromName(string $name): StatusCode` Gives back a HTTP Status Code enum when provided with a valid HTTP status code as a `HTTP_` prefixed string. (such as `'HTTP_200'` or `'HTTP_404'`)
- `ReasonPhrase::fromInteger(int $integer): ReasonPhrase` Gives back a HTTP Reason Phrase enum when provided with a valid HTTP status code as integer. (such as `200` or `404`)
- `ReasonPhrase::fromName(string $name): ReasonPhrase` Gives back a HTTP Reason Phrase enum when provided with a valid HTTP status code as a `HTTP_` prefixed string. (such as `'HTTP_200'` or `'HTTP_404'`)

All of the above methods also have a try variant (such as `Method::tryFromName(?string $name): ?Method`), which returns `null` if an invalid value of the correct type has been given instead of throwing an exception.

Additionally, you can change between Status Code enums and Reason Phrase enums using the following methods:

- `ReasonPhrase::fromStatusCode(StatusCode $statusCode): ReasonPhrase` changes a Status Code enum into the corresponding Reason Phrase enum.
- `StatusCode::fromReasonPhrase(ReasonPhrase $reasonPhrase): StatusCode` changes a Reason Phrase enum into the corresponding Status Code enum.

These methods do not have a try variant.

You can get the respective string or integer representation as usual by reading the `value` attribute on the enum.

License
-------

[](#license)

Copyright Alexander Pas 2021. Distributed under the Boost Software License, Version 1.0. (See accompanying file [LICENSE\_1\_0.txt](LICENSE_1_0.txt) or copy at [https://www.boost.org/LICENSE\_1\_0.txt](https://www.boost.org/LICENSE_1_0.txt))

Notes
-----

[](#notes)

- Support for the HTTP status code 306 has intentionally been removed as it has been defined as Unused in [RFC 7231, Section 6.4.6](https://www.iana.org/go/rfc7231)
- The Methods, Status Codes and Reason Phrases defined in the [Hyper Text Coffee Pot Control Protocol](https://en.wikipedia.org/wiki/HTCPCP) ([RFC 2324](https://www.iana.org/go/rfc2324)) are not supported as they aren't properly registered and provide Methods unique to that specific protocol.
- The [Request Methods specific to WebDAV](https://en.wikipedia.org/wiki/WebDAV) are not supported.

###  Health Score

44

—

FairBetter than 92% of packages

Maintenance35

Infrequent updates — may be unmaintained

Popularity47

Moderate usage in the ecosystem

Community21

Small or concentrated contributor base

Maturity59

Maturing project, gaining track record

 Bus Factor3

3 contributors hold 50%+ of commits

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

1701d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/59f73cf56fea8db5989627d311366d029edc2ce27264d184f61e557d4202917d?d=identicon)[alexanderpas](/maintainers/alexanderpas)

---

Top Contributors

[![alexanderpas](https://avatars.githubusercontent.com/u/373047?v=4)](https://github.com/alexanderpas "alexanderpas (1 commits)")[![chapeupreto](https://avatars.githubusercontent.com/u/834048?v=4)](https://github.com/chapeupreto "chapeupreto (1 commits)")[![drupol](https://avatars.githubusercontent.com/u/252042?v=4)](https://github.com/drupol "drupol (1 commits)")[![Seldaek](https://avatars.githubusercontent.com/u/183678?v=4)](https://github.com/Seldaek "Seldaek (1 commits)")[![sjokkateer](https://avatars.githubusercontent.com/u/27890746?v=4)](https://github.com/sjokkateer "sjokkateer (1 commits)")

---

Tags

hacktoberfesthacktoberfest2021php

###  Code Quality

TestsPHPUnit

Static AnalysisPsalm

Code StyleECS

Type Coverage Yes

### Embed Badge

![Health badge](/badges/alexanderpas-http-enum/health.svg)

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

###  Alternatives

[friendsofsymfony/rest-bundle

This Bundle provides various tools to rapidly develop RESTful API's with Symfony

2.8k73.3M319](/packages/friendsofsymfony-rest-bundle)[php-http/discovery

Finds and installs PSR-7, PSR-17, PSR-18 and HTTPlug implementations

1.3k309.5M1.2k](/packages/php-http-discovery)[pusher/pusher-php-server

Library for interacting with the Pusher REST API

1.5k94.8M293](/packages/pusher-pusher-php-server)[react/http

Event-driven, streaming HTTP client and server implementation for ReactPHP

78026.4M414](/packages/react-http)[php-http/curl-client

PSR-18 and HTTPlug Async client with cURL

48347.0M384](/packages/php-http-curl-client)[smi2/phpclickhouse

PHP ClickHouse Client

84310.1M71](/packages/smi2-phpclickhouse)

PHPackages © 2026

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