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

Abandoned → [ergebnis/http-method](/?search=ergebnis%2Fhttp-method)Library[HTTP &amp; Networking](/categories/http)

localheinz/http-method
======================

Provides constants for HTTP request methods.

2.8.0(8mo ago)953.6k↓100%2[2 PRs](https://github.com/ergebnis/http-method/pulls)MITPHPPHP ~8.1.0 || ~8.2.0 || ~8.3.0 || ~8.4.0 || ~8.5.0CI passing

Since Jul 3Pushed 1mo ago3 watchersCompare

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

READMEChangelog (10)Dependencies (12)Versions (17)Used By (0)

http-method
===========

[](#http-method)

[![Integrate](https://github.com/ergebnis/http-method/workflows/Integrate/badge.svg)](https://github.com/ergebnis/http-method/actions)[![Merge](https://github.com/ergebnis/http-method/workflows/Merge/badge.svg)](https://github.com/ergebnis/http-method/actions)[![Release](https://github.com/ergebnis/http-method/workflows/Release/badge.svg)](https://github.com/ergebnis/http-method/actions)[![Renew](https://github.com/ergebnis/http-method/workflows/Renew/badge.svg)](https://github.com/ergebnis/http-method/actions)

[![Code Coverage](https://camo.githubusercontent.com/5f42073b6dd18615a9c921164d1fad3b138eafd3d4d2c1d79e319e7f39996e9e/68747470733a2f2f636f6465636f762e696f2f67682f65726765626e69732f687474702d6d6574686f642f6272616e63682f6d61696e2f67726170682f62616467652e737667)](https://codecov.io/gh/ergebnis/http-method)

[![Latest Stable Version](https://camo.githubusercontent.com/3771685d1d2a883ee5cc573ba3918bb365faf5da91fe26f5bb7709dc4140b245/68747470733a2f2f706f7365722e707567782e6f72672f65726765626e69732f687474702d6d6574686f642f762f737461626c65)](https://packagist.org/packages/ergebnis/http-method)[![Total Downloads](https://camo.githubusercontent.com/e4c44f08559fbf8255b8407b5f3de40271e542fbcabd5a706104c27e4c10ea6f/68747470733a2f2f706f7365722e707567782e6f72672f65726765626e69732f687474702d6d6574686f642f646f776e6c6f616473)](https://packagist.org/packages/ergebnis/http-method)[![Monthly Downloads](https://camo.githubusercontent.com/c94ff735df312a334c14c90da5e9130b6de5012c72d4c854e6bddbb861dc398f/687474703a2f2f706f7365722e707567782e6f72672f65726765626e69732f687474702d6d6574686f642f642f6d6f6e74686c79)](https://packagist.org/packages/ergebnis/http-method)

This project provides a [`composer`](https://getcomposer.org) package with constants for HTTP request methods.

Motivation
----------

[](#motivation)

Several PHP frameworks and packages come with their own abstractions of HTTP request and response objects. Some of them provide constants for

- HTTP request method names
- HTTP response status codes

so that a developer can refer to these by using named constants instead of magic numbers or magic strings.

Here are a few examples of HTTP request abstractions which provide constants for HTTP request methods:

- [`Symfony\Component\HttpFoundation\Request`](https://github.com/symfony/http-foundation/blob/v4.3.2/Request.php#L41-L50)
- [`Zend\Http\Request`](https://github.com/zendframework/zend-http/blob/release-2.10.0/src/Request.php#L26-L35)

Here are a few examples of HTTP response abstractions which provide constants for HTTP response status codes:

- [`Symfony\Component\HttpFoundation\Response`](https://github.com/symfony/http-foundation/blob/v4.3.2/Response.php#L21-L88)
- [`Zend\Http\Response`](https://github.com/zendframework/zend-http/blob/release-2.10.0/src/Response.php#L24-L88)

Here are a few examples of interfaces providing constants for HTTP request methods and HTTP response status codes:

- [`Fig\Http\Message\RequestMethodInterface`](https://github.com/php-fig/http-message-util/blob/1.1.3/src/RequestMethodInterface.php#L24-L33)
- [`Fig\Http\Message\StatusCodeInterface`](https://github.com/php-fig/http-message-util/blob/1.1.3/src/StatusCodeInterface.php#L39-L106)

However, a developer might use an abstraction that either does not provide any constants at all, or only provides a subset of the constants required for the specific case.

The excellent library [`teapot/status-code`](https://github.com/teapot-php/status-code) already provides HTTP status codes that are standardized by RFCs, as well as a range of vendor-specific HTTP status codes.

In a similar fashion, this library here aims to provide a collection of interfaces with constants for HTTP request methods that are standardized by RFCs, as well as additional vendor-specific HTTP request methods.

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

[](#installation)

Run

```
composer require ergebnis/http-method
```

Usage
-----

[](#usage)

The interface [`Ergebnis\Http\Method`](/src/Method.php) provides constants for all of the HTTP request methods that are standardized by

- [RFC 5789](https://tools.ietf.org/html/rfc5789)
- [RFC 7231](https://tools.ietf.org/html/rfc7231)

namely

- `CONNECT`
- `DELETE`
- `GET`
- `HEAD`
- `OPTIONS`
- `PATCH`
- `POST`
- `PUT`
- `TRACE`

The interface [`Ergebnis\Http\Method\WebDav`](/src/Method/WebDav.php) provides constants for all of the HTTP request methods that are standardized by

- [RFC 3648](https://tools.ietf.org/html/rfc3648)
- [RFC 3744](https://tools.ietf.org/html/rfc3744)
- [RFC 4437](https://tools.ietf.org/html/rfc4437)
- [RFC 4791](https://tools.ietf.org/html/rfc4791)
- [RFC 4918](https://tools.ietf.org/html/rfc4918)
- [RFC 5323](https://tools.ietf.org/html/rfc5323)
- [RFC 5789](https://tools.ietf.org/html/rfc5789)
- [RFC 5842](https://tools.ietf.org/html/rfc5842)
- [RFC 7231](https://tools.ietf.org/html/rfc7231)

namely

- `ACL`
- `BIND`
- `CONNECT`
- `COPY`
- `DELETE`
- `GET`
- `HEAD`
- `LOCK`
- `MKCALENDAR`
- `MKCOL`
- `MKREDIRECTREF`
- `MOVE`
- `OPTIONS`
- `ORDERPATCH`
- `PATCH`
- `POST`
- `PROPFIND`
- `PROPPATCH`
- `PUT`
- `REBIND`
- `SEARCH`
- `TRACE`
- `UNBIND`
- `UNLOCK`
- `UPDATEREDIRECTREF`

The interface [`Ergebnis\Http\Method\Vendor\SquidCache`](/src/Method/Vendor/SquidCache.php) provides constants for a suggest HTTP request method used for purging items from the cache, namely

- `PURGE`

The interface [`Ergebnis\Http\Method\Vendor\VarnishCache`](/src/Method/Vendor/VarnishCache.php) provides constants for a suggest HTTP request method used for invalidating and purging items from the cache, namely

- `BAN`
- `PURGE`

To use these constants, import the interfaces and refer to the constants instead of using magic strings:

```
