Skip to content

Commit 221a446

Browse files
committed
1 parent 3267c60 commit 221a446

File tree

1 file changed

+68
-1
lines changed

1 file changed

+68
-1
lines changed

README.md

Lines changed: 68 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# chillerlan/php-httpinterface
22

3-
A http client wrapper/PSR-7/PSR-17 implementation for PHP 7.2+.
3+
A http client wrapper/PSR-7/PSR-17/PSR-18 implementation for PHP 7.2+.
44

55
[![version][packagist-badge]][packagist]
66
[![license][license-badge]][license]
@@ -25,3 +25,70 @@ A http client wrapper/PSR-7/PSR-17 implementation for PHP 7.2+.
2525
[donate-badge]: https://img.shields.io/badge/donate-paypal-ff33aa.svg?style=flat-square
2626
[donate]: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=WLYUNAT9ZTJZ4
2727

28+
# Documentation
29+
30+
## Requirements
31+
- PHP 7.2+
32+
- the cURL extension if you plan to use the `CurlClient` class
33+
34+
## Installation
35+
**requires [composer](https://getcomposer.org)**
36+
37+
*composer.json* (note: replace `dev-master` with a [version boundary](https://getcomposer.org/doc/articles/versions.md))
38+
```json
39+
{
40+
"require": {
41+
"php": "^7.2",
42+
"chillerlan/php-httpinterface": "dev-master"
43+
}
44+
}
45+
```
46+
47+
### Manual installation
48+
Download the desired version of the package from [master](https://github.com/chillerlan/php-httpinterface/archive/master.zip) or
49+
[release](https://github.com/chillerlan/php-httpinterface/releases) and extract the contents to your project folder. After that:
50+
- run `composer install` to install the required dependencies and generate `/vendor/autoload.php`.
51+
- if you use a custom autoloader, point the namespace `chillerlan\HTTP` to the folder `src` of the package
52+
53+
Profit!
54+
55+
## Usage
56+
57+
### [`HTTPClientInterface`](https://github.com/chillerlan/php-httpinterface/blob/master/src/HTTPClientInterface.php)
58+
A `HTTPClientInterface` is usually invoked with a [`HTTPOptions`](https://github.com/chillerlan/php-httpinterface/blob/master/src/HTTPOptions.php) object as the first (optional) parameter,
59+
and - depending on the client - followed by one or more optional [PSR-17](https://www.php-fig.org/psr/psr-17/) message factories.
60+
```php
61+
$options = new HTTPOptions([
62+
'ca_info' => '/path/to/cacert.pem',
63+
'user_agent' => 'my cool user agent 1.0',
64+
]);
65+
66+
$http = new CurlClient($options, $myRequestFactory, $myResponseFactory);
67+
```
68+
You can now fire a request via the implemented [PSR-18](https://www.php-fig.org/psr/psr-18/) method `ClientInterface::sendRequest()`,
69+
using an existing [PSR-7](https://www.php-fig.org/psr/psr-7/) `RequestInterface`...
70+
```php
71+
use chillerlan\HTTP\Psr7\Request;
72+
73+
$request = new Request('GET', 'https://www.example.com?foo=bar');
74+
75+
$http->sendRequest($request);
76+
```
77+
...or you can use the `HTTPClientInterface::request()` method, which creates a new request using the provided (if any) factories.
78+
The `HTTPClientInterface` also provides constants for the HTTP methods via the [`RequestMethodInterface`](https://github.com/php-fig/http-message-util/blob/master/src/RequestMethodInterface.php).
79+
```php
80+
$http->request('https://www.example.com', $http::METHOD_GET, ['foo' => 'bar']);
81+
```
82+
Both methods will return a PSR-7 `ResponseInterface`.
83+
84+
### PSR-7 Message helpers
85+
These static methods can be found in the `chillerlan\HTTP\Psr7` namespace
86+
87+
88+
### PSR-17 Factory helpers
89+
These static methods can be found in the `chillerlan\HTTP\Psr17` namespace:
90+
91+
- `create_server_request_from_globals()` - creates a PSR-7 `ServerRequestInterface` object that is populated with the GPCS superglobals.
92+
- `create_uri_from_globals()` - creates a PSR-7 `UriInterface` object that is populated with values from `$_SERVER`.
93+
- `create_stream(string $content = '')` - creates a PSR-7 `StreamInterface` object from a string.
94+
- `create_stream_from_input($in = null)` - creates a PSR-7 `StreamInterface` object from guessed input (string/scalar, file path, resource, object)

0 commit comments

Comments
 (0)