Skip to content

Commit c14dfd7

Browse files
NyholmMárk Sági-Kazár
authored and
Márk Sági-Kazár
committed
Add integrations, add symfony bundle documentation
1 parent 1f6cdbc commit c14dfd7

12 files changed

+300
-15
lines changed

_static/custom.css

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.row-even .line-block, .row-odd .line-block {
2+
margin-left: 0;
3+
}

assets/img/debug-toolbar.png

6.99 KB
Loading

conf.py

+1
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@
155155
html_static_path = ['_static']
156156

157157
def setup(app):
158+
app.add_stylesheet('custom.css')
158159
app.add_stylesheet('highlight.css')
159160

160161
# Add any extra paths that contain custom files (such as robots.txt or

httplug/application-developers.rst

-11
This file was deleted.

httplug/introduction.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ Usage
4444

4545
There are two main use cases for HTTPlug:
4646

47-
* usage in an application that executes HTTP requests (see :doc:`application-developers`).
48-
* usage in a reusable package that executes HTTP requests (see :doc:`library-developers`).
47+
* Usage in an application that executes HTTP requests (see :doc:`tutorial` and :doc:`../integrations/index`);
48+
* Usage in a reusable package that executes HTTP requests (see :doc:`library-developers`).
4949

5050
History
5151
-------

httplug/tutorial.rst

+6
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@ take into account when building a reusable package.
1111

1212
We use Composer_ for dependency management. Install it if you don't have it yet.
1313

14+
.. note::
15+
16+
If you are using a framework, check the :doc:`../integrations/index` to see if
17+
there is an integration available. Framework integrations will simplify the way
18+
you set up clients, letting you focus on handling the requests.
19+
1420
Setting up the project
1521
----------------------
1622

httplug/usage.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@ HTTPlug is relevant for three groups of users:
77
:maxdepth: 1
88

99
Library users <users>
10-
Application developers <application-developers>
10+
Application developers <tutorial>
1111
Library developers <library-developers>
1212

index.rst

+2
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ for discussion around a future HTTP client PSR.
7171
clients
7272
plugins/index
7373

74+
integrations/index
75+
7476
.. toctree::
7577
:hidden:
7678
:caption: Components

integrations/index.rst

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
Framework Integrations
2+
======================
3+
4+
HTTPlug provides the following framework integrations:
5+
6+
.. toctree::
7+
8+
symfony-bundle
9+
symfony-full-configuration

integrations/symfony-bundle.rst

+198
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,198 @@
1+
Symfony Bundle
2+
==============
3+
4+
This bundle integrate HTTPlug with the Symfony framework. The bundle helps to register services for all your clients and makes sure all the configuration is in one place. The bundle also feature a toolbar plugin with information about your requests.
5+
6+
This guide explains how to configure HTTPlug in the Symfony framework. See the :doc:`../httplug/tutorial` for examples how to use HTTPlug in general.
7+
8+
Installation
9+
````````````
10+
11+
Install the HTTPlug bundle with composer and enable it in your AppKernel.php.
12+
13+
.. code-block:: bash
14+
15+
$ composer require php-http/httplug-bundle
16+
17+
.. code-block:: php
18+
19+
public function registerBundles()
20+
{
21+
$bundles = array(
22+
// ...
23+
new Http\HttplugBundle\HttplugBundle(),
24+
);
25+
}
26+
27+
You will find all available configuration at the :doc:`full configuration </integrations/symfony-full-configuration>` page.
28+
29+
Usage
30+
`````
31+
32+
.. code-block:: yaml
33+
34+
httplug:
35+
plugins:
36+
logger: ~
37+
clients:
38+
acme:
39+
factory: 'httplug.factory.guzzle6'
40+
plugins: ['httplug.plugin.logger']
41+
config:
42+
verify: false
43+
timeout: 2
44+
45+
.. code-block:: php
46+
47+
$request = $this->container->get('httplug.message_factory')->createRequest('GET', 'http://example.com');
48+
$response = $this->container->get('httplug.client.acme')->sendRequest($request);
49+
50+
51+
Web Debug Toolbar
52+
`````````````````
53+
.. image:: /assets/img/debug-toolbar.png
54+
:align: right
55+
:width: 120px
56+
57+
When using a client configured with ``HttplugBundle``, you will get debug information in the web debug toolbar. It will tell you how many request were made and how many of those that were successful or not. It will also show you detailed information about each request.
58+
59+
Discovery of Factory Classes
60+
````````````````````````````
61+
62+
If you want the bundle to automatically find usable factory classes, install and enable ``puli/symfony-bundle``. If you do not want use auto discovery, you need to specify all the factory classes for you client. The following example show how you configure factory classes using Guzzle:
63+
64+
.. code-block:: yaml
65+
66+
httplug:
67+
classes:
68+
client: Http\Adapter\Guzzle6\Client
69+
message_factory: Http\Message\MessageFactory\GuzzleMessageFactory
70+
uri_factory: Http\Message\UriFactory\GuzzleUriFactory
71+
stream_factory: Http\Message\StreamFactory\GuzzleStreamFactory
72+
73+
74+
75+
Configure Clients
76+
`````````````````
77+
78+
You can configure your clients with default options. These default values will be specific to you client you are using. The clients are later registered as services.
79+
80+
.. code-block:: yaml
81+
82+
httplug:
83+
clients:
84+
my_guzzle5:
85+
factory: 'httplug.factory.guzzle5'
86+
config:
87+
# These options are given to Guzzle without validation.
88+
defaults:
89+
verify_ssl: false
90+
timeout: 4
91+
acme:
92+
factory: 'httplug.factory.curl'
93+
config:
94+
78: 4 #CURLOPT_CONNECTTIMEOUT
95+
96+
.. code-block:: php
97+
98+
$httpClient = $this->container->get('httplug.client.my_guzzle5');
99+
$httpClient = $this->container->get('httplug.client.curl');
100+
101+
// will be the same as ``httplug.client.my_guzzle5``
102+
$httpClient = $this->container->get('httplug.client');
103+
104+
The bundle has client factory services that you can use to build your client. If you need a very custom made client you could create your own factory service implementing ``Http\HttplugBudle\ClientFactory\ClientFactory``. The built-in services are:
105+
106+
* ``httplug.factory.curl``
107+
* ``httplug.factory.guzzle5``
108+
* ``httplug.factory.guzzle6``
109+
* ``httplug.factory.react``
110+
* ``httplug.factory.socket``
111+
112+
Plugins
113+
```````
114+
115+
You can configure the clients with plugins. You can choose to use a built in plugin in the ``php-http/plugins`` package or provide a plugin of your own. The order of the specified plugin does matter.
116+
117+
.. code-block:: yaml
118+
119+
// services.yml
120+
acme_plugin:
121+
class: Acme\Plugin\MyCustomPlugin
122+
arguments: ["%some_parameter%"]
123+
124+
.. code-block:: yaml
125+
126+
// config.yml
127+
httplug:
128+
plugins:
129+
cache:
130+
cache_pool: 'my_cache_pool'
131+
clients:
132+
acme:
133+
factory: 'httplug.factory.guzzle6'
134+
plugins: ['acme_plugin', 'httplug.plugin.cache', 'httplug.plugin.retry']
135+
136+
137+
Authentication
138+
``````````````
139+
140+
You can configure a client with authentication. Valid authentication types are ``basic``, ``bearer``, ``service`` and ``wsse``. See more examples at the :doc:`full configuration </integrations/symfony-full-configuration>`.
141+
142+
.. code-block:: yaml
143+
144+
// config.yml
145+
httplug:
146+
plugins:
147+
authentication:
148+
my_wsse:
149+
type: 'wsse'
150+
username: 'my_username'
151+
password: 'p4ssw0rd'
152+
153+
clients:
154+
acme:
155+
factory: 'httplug.factory.guzzle6'
156+
plugins: ['httplug.plugin.authentication.my_wsse']
157+
158+
159+
List of Services
160+
````````````````
161+
162+
+-------------------------------------+-------------------------------------------------------------------------+
163+
| Service id | Description |
164+
+=====================================+=========================================================================+
165+
| ``httplug.message_factory`` | Service* that provides the `Http\Message\MessageFactory` |
166+
+-------------------------------------+-------------------------------------------------------------------------+
167+
| ``httplug.uri_factory`` | Service* that provides the `Http\Message\UriFactory` |
168+
+-------------------------------------+-------------------------------------------------------------------------+
169+
| ``httplug.stream_factory`` | Service* that provides the `Http\Message\StreamFactory` |
170+
+-------------------------------------+-------------------------------------------------------------------------+
171+
| ``httplug.client.[name]`` | There is one service per named client. |
172+
+-------------------------------------+-------------------------------------------------------------------------+
173+
| ``httplug.client`` | | If there is a client named "default", this service is an alias to |
174+
| | | that client, otherwise it is an alias to the first client configured. |
175+
+-------------------------------------+-------------------------------------------------------------------------+
176+
| | ``httplug.plugin.content_length`` | | These are plugins that are enabled by default. |
177+
| | ``httplug.plugin.decoder`` | | These services are private and should only be used to configure |
178+
| | ``httplug.plugin.error`` | | clients or other services. |
179+
| | ``httplug.plugin.logger`` | |
180+
| | ``httplug.plugin.redirect`` | |
181+
| | ``httplug.plugin.retry`` | |
182+
| | ``httplug.plugin.stopwatch`` | |
183+
+-------------------------------------+-------------------------------------------------------------------------+
184+
| | ``httplug.plugin.cache`` | | These are plugins that are disabled by default and only get |
185+
| | ``httplug.plugin.cookie`` | | activated when configured. |
186+
| | ``httplug.plugin.history`` | | These services are private and should only be used to configure |
187+
| | | clients or other services. |
188+
+-------------------------------------+-------------------------------------------------------------------------+
189+
190+
\* *These services are always an alias to another service. You can specify your own service or leave the default, which is the same name with `.default` appended.*
191+
192+
193+
Usage for Reusable Bundles
194+
``````````````````````````
195+
196+
Rather than code against specific HTTP clients, you want to use the HTTPlug ``Client`` interface. To avoid building your own infrastructure to define services for the client, simply ``require: php-http/httplug-bundle`` in your bundles ``composer.json``. You SHOULD provide a configuration option to specify the which HTTP client service to use for each of your services. This option should default to ``httplug.client``. This way, the default case needs no additional configuration for your users, but they have the option of using specific clients with each of your services.
197+
198+
The only steps they need is ``require`` one of the adapter implementations in their projects ``composer.json`` and instantiating the ``HttplugBundle`` in their kernel.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
Full configuration
2+
==================
3+
4+
This page shows an example of all configuration values provided by the bundle.
5+
6+
.. code-block:: yaml
7+
8+
// config.yml
9+
httplug:
10+
main_alias:
11+
client: httplug.client.default
12+
message_factory: httplug.message_factory.default
13+
uri_factory: httplug.uri_factory.default
14+
stream_factory: httplug.stream_factory.default
15+
classes:
16+
# uses discovery if not specified
17+
client: ~
18+
message_factory: ~
19+
uri_factory: ~
20+
stream_factory: ~
21+
22+
plugins:
23+
authentication:
24+
my_basic:
25+
type: 'basic'
26+
username: 'my_username'
27+
password: 'p4ssw0rd'
28+
my_wsse:
29+
type: 'wsse'
30+
username: 'my_username'
31+
password: 'p4ssw0rd'
32+
my_bearer:
33+
type: 'bearer'
34+
token: 'authentication_token_hash'
35+
my_service:
36+
type: 'service'
37+
service: 'my_authentication_service'
38+
cache:
39+
enabled: true
40+
cache_pool: 'my_cache_pool'
41+
stream_factory: 'httplug.stream_factory'
42+
config:
43+
default_ttl: 3600
44+
respect_cache_headers: true
45+
cookie:
46+
enabled: true
47+
cookie_jar: my_cookie_jar
48+
decoder:
49+
enabled: true
50+
use_content_encoding: true
51+
history:
52+
enabled: true
53+
journal: my_journal
54+
logger:
55+
enabled: true
56+
logger: 'logger'
57+
formatter: null
58+
redirect:
59+
enabled: true
60+
preserve_header: true
61+
use_default_for_multiple: true
62+
retry:
63+
enabled: true
64+
retry: 1
65+
stopwatch:
66+
enabled: true
67+
stopwatch: 'debug.stopwatch'
68+
clients:
69+
acme:
70+
factory: 'httplug.factory.guzzle6'
71+
plugins: ['httplug.plugin.authentication.my_wsse', 'httplug.plugin.cache', 'httplug.plugin.retry']
72+
config:
73+
verify: false
74+
timeout: 2
75+
# more options to the guzzle 6 constructor
76+

spelling_word_list.txt

+2-1
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,14 @@ plugins
1717
matchers
1818
param
1919
params
20+
Puli
2021
rebase
2122
Semver
2223
sexualized
2324
sublicense
2425
sync
26+
toolbar
2527
username
2628
whitelist
2729
wiki
2830
workflow
29-
Puli

0 commit comments

Comments
 (0)