You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
**Note:** If Composer is not installed [globally](https://getcomposer.org/doc/00-intro.md#globally) then you may need to run the preceding Composer commands using ``php composer.phar`` (where ``composer.phar`` is the path to your copy of Composer), instead of just ``composer``.
24
+
```
25
+
composer require guzzlehttp/command
26
+
```
29
27
30
28
## Service Clients
31
29
32
30
Service Clients are web service clients that implement the
33
-
``GuzzleHttp\Command\ServiceClientInterface`` and use an underlying Guzzle HTTP
34
-
client (``GuzzleHttp\Client``) to communicate with the service. Service clients
35
-
create and execute **commands** (``GuzzleHttp\Command\CommandInterface``),
31
+
`GuzzleHttp\Command\ServiceClientInterface` and use an underlying Guzzle HTTP
32
+
client (`GuzzleHttp\ClientInterface`) to communicate with the service. Service
33
+
clients create and execute *commands* (`GuzzleHttp\Command\CommandInterface`),
36
34
which encapsulate operations within the web service, including the operation
37
35
name and parameters. This library provides a generic implementation of a service
38
-
client: the ``GuzzleHttp\Command\ServiceClient`` class.
36
+
client: the `GuzzleHttp\Command\ServiceClient` class.
39
37
40
38
## Instantiating a Service Client
41
39
42
-
@TODO Add documentation
40
+
The provided service client implementation (`GuzzleHttp\Command\ServiceClient`)
41
+
can be instantiated by providing the following arguments:
43
42
44
-
*``ServiceClient``'s constructor
45
-
* Transformer functions (``$commandToRequestTransformer`` and ``$responseToResultTransformer``)
46
-
* The ``HandlerStack``
43
+
1. A fully-configured Guzzle HTTP client that will be used to perform the
44
+
underlying HTTP requests. That is, an instance of an object implementing
45
+
`GuzzleHttp\ClientInterface` such as `new GuzzleHttp\Client()`.
46
+
1. A callable that transforms a Command into a Request. The function should
47
+
accept a `GuzzleHttp\Command\CommandInterface` object and return a
48
+
`Psr\Http\Message\RequestInterface` object.
49
+
1. A callable that transforms a Response into a Result. The function should
50
+
accept a `Psr\Http\Message\ResponseInterface` object and optionally a
51
+
`Psr\Http\Message\RequestInterface` object, and return a
52
+
`GuzzleHttp\Command\ResultInterface` object.
53
+
1. Optionally, a Guzzle HandlerStack (`GuzzleHttp\HandlerStack`), which can be
54
+
used to add command-level middleware to the service client.
55
+
56
+
Below is an example configured to send and receive JSON payloads:
57
+
58
+
```php
59
+
use GuzzleHttp\Command\CommandInterface;
60
+
use GuzzleHttp\Command\Result;
61
+
use GuzzleHttp\Command\ResultInterface;
62
+
use GuzzleHttp\Command\ServiceClient;
63
+
use GuzzleHttp\Psr7\Request;
64
+
use GuzzleHttp\UriTemplate\UriTemplate;
65
+
use GuzzleHttp\Utils;
66
+
use Psr\Http\Message\RequestInterface;
67
+
use Psr\Http\Message\ResponseInterface;
68
+
69
+
$client = new ServiceClient(
70
+
new HttpClient(),
71
+
function (CommandInterface $command): RequestInterface {
0 commit comments