Skip to content

Commit 058c08d

Browse files
authored
Merge pull request #25 from localheinz/feature/readme
Enhancement: Update README.md
2 parents ba70301 + c8b5c96 commit 058c08d

File tree

1 file changed

+90
-5
lines changed

1 file changed

+90
-5
lines changed

README.md

Lines changed: 90 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,31 @@
66

77
Provides constants for HTTP request methods, inspired by [`teapot/status-code`](https://github.com/teapot-php/status-code).
88

9+
## Motivation
10+
11+
Several PHP frameworks come with their own abstractions of HTTP request and response objects. Some of them provide constants for
12+
13+
- HTTP request method names
14+
- HTTP response status codes
15+
16+
so that a developer can refer to these by using named constants instead of magic numbers or magic strings.
17+
18+
Here are a few examples of HTTP request abstractions which provide constants for HTTP request methods:
19+
20+
* [`Symfony\Component\HttpFoundation\Request`](https://github.com/symfony/http-foundation/blob/v4.3.2/Request.php#L41-L50)
21+
* [`Zend\Http\Request`](https://github.com/zendframework/zend-http/blob/release-2.10.0/src/Request.php#L26-L35)
22+
23+
Here are a few examples of HTTP response abstractions which provide constants for HTTP response status codes:
24+
25+
* [`Symfony\Component\HttpFoundation\Response`](https://github.com/symfony/http-foundation/blob/v4.3.2/Response.php#L21-L88)
26+
* [`Zend\Http\Request`](https://github.com/zendframework/zend-http/blob/release-2.10.0/src/Response.php#L24-L88)
27+
28+
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.
29+
30+
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.
31+
32+
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.
33+
934
## Installation
1035

1136
Run
@@ -16,7 +41,12 @@ $ composer require localheinz/http-method
1641

1742
## Usage
1843

19-
The interface `Localheinz\Http\Method` provides constants for all of the HTTP request methods:
44+
The interface [`Localheinz\Http\Method`](/src/Method.php) provides constants for all of the HTTP request methods that are standardized by
45+
46+
* [RFC 5789](https://tools.ietf.org/html/rfc5789)
47+
* [RFC 7231](https://tools.ietf.org/html/rfc7231)
48+
49+
namely
2050

2151
* `CONNECT`
2252
* `DELETE`
@@ -25,23 +55,78 @@ The interface `Localheinz\Http\Method` provides constants for all of the HTTP re
2555
* `OPTIONS`
2656
* `PATCH`
2757
* `POST`
28-
* `PURGE`
2958
* `PUT`
3059
* `TRACE`
3160

32-
Import the interface and use the constants instead of using magic strings:
61+
The interface [`Localheinz\Http\Method\WebDav`](/src/Method/WebDav.php) provides constants for all of the HTTP request methods that are standardized by
62+
63+
- [RFC 3648](https://tools.ietf.org/html/rfc3648)
64+
- [RFC 3744](https://tools.ietf.org/html/rfc3744)
65+
- [RFC 4437](https://tools.ietf.org/html/rfc4437)
66+
- [RFC 4791](https://tools.ietf.org/html/rfc4791)
67+
- [RFC 4918](https://tools.ietf.org/html/rfc4918)
68+
- [RFC 5323](https://tools.ietf.org/html/rfc5323)
69+
- [RFC 5789](https://tools.ietf.org/html/rfc5789)
70+
- [RFC 5842](https://tools.ietf.org/html/rfc5842)
71+
- [RFC 7231](https://tools.ietf.org/html/rfc7231)
72+
73+
namely
74+
75+
- `ACL`
76+
- `BIND`
77+
- `CONNECT`
78+
- `COPY`
79+
- `DELETE`
80+
- `GET`
81+
- `HEAD`
82+
- `LOCK`
83+
- `MKCALENDAR`
84+
- `MKCOL`
85+
- `MKREDIRECTREF`
86+
- `MOVE`
87+
- `OPTIONS`
88+
- `ORDERPATCH`
89+
- `PATCH`
90+
- `POST`
91+
- `PROPFIND`
92+
- `PROPPATCH`
93+
- `PUT`
94+
- `REBIND`
95+
- `SEARCH`
96+
- `TRACE`
97+
- `UNBIND`
98+
- `UNLOCK`
99+
- `UPDATEREDIRECTREF`
100+
101+
The interface [`Localheinz\Http\Method\Vendor\SquidCache`](/src/Method/Vendor/SquidCache.php) provides constants for a suggest HTTP request method used for purging items from the cache,
102+
namely
103+
104+
- `PURGE`
105+
106+
The interface [`Localheinz\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
107+
108+
- `BAN`
109+
- `PURGE`
110+
111+
To use these constants, import the interfaces and refer to the constants instead of using magic strings:
33112

34113
```php
35114
use Localheinz\Http\Method;
36-
use Psr\Http\Message\RequestFactoryInterface;
115+
use Psr\Http\Client;
116+
use Psr\Http\Message;
37117

38-
/** @var RequestFactoryInterface $requestFactory */
118+
/** @var Message\RequestFactoryInterface $requestFactory */
39119
$request = $requestFactory->create(
40120
Method::GET,
41121
'https://localheinz.com/blog'
42122
);
123+
124+
/** @var Client\ClientInterface $httpClient */
125+
$httpClient->sendRequest($request);
43126
```
44127

128+
:bulb: If you are aware of any other - either standardized or vendor-specific - HTTP methods that are used in the wild, please let me know!
129+
45130
## Changelog
46131

47132
Please have a look at [`CHANGELOG.md`](CHANGELOG.md).

0 commit comments

Comments
 (0)