|
1 | 1 | # HTTP Adapter
|
2 | 2 |
|
3 |
| -**This is the documentation for HTTP Adapter and it's software components.** |
| 3 | +**This is the documentation for the Httplug web client abstraction and the other PHP-HTTP components.** |
4 | 4 |
|
5 |
| -The HTTP Adapter abstracts from PHP HTTP clients that are based on [PSR-7](http://www.php-fig.org/psr/psr-7/). |
| 5 | +Httplug abstracts from HTTP clients written in PHP that are based on [PSR-7](http://www.php-fig.org/psr/psr-7/). |
6 | 6 | It allows you to write reusable libraries and applications that need a HTTP client without binding to a specific implementation.
|
7 | 7 |
|
8 |
| -## History |
9 |
| - |
10 |
| -This project has been started by [Eric Geloen](https://github.com/egeloen) as [Ivory Http Adapter](https://github.com/egeloen/ivory-http-adapter). It never made it to be really stable, but it relied on PSR-7 which was not stable either that time. Because of the constantly changing PSR-7 Eric had to rewrite the library over and over again (at least the message handling part, which in most cases affected every adapters). |
11 |
| - |
12 |
| -in 2015 a decision has been made to move the library to it's own organization, so PHP HTTP was born. |
| 8 | +If you do not have access to a dependency injection system, the [Discovery](discovery.md) system can be used to automatically locate a suitable client and a PSR-7 message factory. |
13 | 9 |
|
14 | 10 |
|
15 | 11 | ## Getting started
|
16 | 12 |
|
17 |
| -HTTP Adapter is separated into several components: |
18 |
| - |
19 |
| -- Adapter contract |
20 |
| -- Client contract |
21 |
| -- Adapter client |
22 |
| -- Adapter implementations |
23 |
| -- Helpers |
24 |
| - |
25 |
| - |
26 |
| -### Installation |
27 |
| - |
28 |
| -There are many strategies how adapters and other components can be installed. However they are the same in one thing: they can be installed via [Composer](http://getcomposer.org/): |
29 |
| - |
30 |
| -``` bash |
31 |
| -$ composer require php-http/adapter |
32 |
| -``` |
33 |
| - |
| 13 | +Read our [tutorial](tutorial.md). |
34 | 14 |
|
35 |
| -#### Installation in a reusable package |
36 | 15 |
|
37 |
| -In many cases packages are designed to be reused from the very beginning. For example API clients are usually used in other packages/applications, not on their own. |
| 16 | +## Overview |
38 | 17 |
|
39 |
| -In these cases it is always a good idea not to rely on a concrete implementation (like Guzzle), but only require some implementation of an HTTP Adapter. With Composer, it is possible: |
| 18 | +PHP-HTTP is separated into several packages: |
40 | 19 |
|
41 |
| -``` json |
42 |
| -{ |
43 |
| - "require": { |
44 |
| - "php-http/adapter-implementation": "^1.0" |
45 |
| - } |
46 |
| -} |
47 |
| -``` |
| 20 | +- [Httplug](httplug.md), the HTTP client abstraction to send PSR-7 requests without binding to a specific implementation; |
| 21 | +- [Message Factory](message-factory.md) to create PSR-7 requests without binding to a specific implementation; |
| 22 | +- [Discovery](discovery.md) to automatically locate a suitable Httplug implementation and PSR-7 message factory. |
| 23 | +- [Utilities](utils.md) for convenient sending of HTTP requests. |
48 | 24 |
|
49 |
| -This allows the end user to choose a concrete implementation when installs the package. Of course, during development a concrete implementation is needed: |
| 25 | +See (package overview)[package-overview.md] for a complete list. |
50 | 26 |
|
51 | 27 |
|
52 |
| -``` json |
53 |
| -{ |
54 |
| - "require-dev": { |
55 |
| - "php-http/guzzle6-adapter": "^1.0" |
56 |
| - } |
57 |
| -} |
58 |
| -``` |
59 |
| - |
60 |
| - |
61 |
| -Another good practice if the package works out-of-the-box, no or only minimal configuration is needed. While not requiring a concrete implementation is great, it also means that the end user would have to always inject the installed adapter (which is the right, but not a convenient solution). To solve this, there is a discovery components which finds and resolves other installed components: |
62 |
| - |
63 |
| -``` json |
64 |
| -{ |
65 |
| - "require": { |
66 |
| - "php-http/discovery": "^1.0" |
67 |
| - } |
68 |
| -} |
69 |
| -``` |
70 |
| - |
71 |
| -Read more about it in the [Discovery](discovery.md) part. |
72 |
| - |
73 |
| - |
74 |
| -#### Installation in an end user package |
75 |
| - |
76 |
| -When installing in an application or a non-reusable package, requiring the virtual package doesn't really make sense. However there are a few things which should be taken into consideration before choosing an adapter: |
77 |
| - |
78 |
| -- It is possible that some other package already has an HTTP Client requirement. It can be confusing to have more than one HTTP Client installed, so always check your other requirements and choose an adapter based on that. |
79 |
| -- Some adapters support parallel requests, some only emulate them. If parallel requests are needed, use one which supports it. |
| 28 | +## History |
80 | 29 |
|
81 |
| -Installing an implementation is easy: |
| 30 | +This project has been started by [Eric Geloen](https://github.com/egeloen) as [Ivory Http Adapter](https://github.com/egeloen/ivory-http-adapter). It never made it to a stable release, but it relied on PSR-7 which was not stable either that time. Because of the constantly changing PSR-7, Eric had to rewrite the library over and over again (at least the message handling part, which in most cases affected every adapter as well). |
82 | 31 |
|
83 |
| -``` bash |
84 |
| -$ composer require php-http/*-adapter |
85 |
| -``` |
| 32 | +In 2015, a decision has been made to move the library to it's own organization, so PHP HTTP was born. |
86 | 33 |
|
87 |
| -_Replace * with any supported adapter name_ |
| 34 | +See (upgrading)[upgrading.md] for a guide how to migrate your code from the Ivory adapter to Httplug. |
0 commit comments