Skip to content

Commit 86f22e0

Browse files
Add documentation
1 parent 9df099b commit 86f22e0

1 file changed

Lines changed: 26 additions & 0 deletions

File tree

README.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,32 @@
44
API for "the software to mock third-party responses" to include in your application's API tests.
55
 
66
 
7+
8+
## Use Proxy / Automatic Mode
9+
To automatically forward requests to the API mock there is the possibility to use a `HandlerStack` for `Guzzle`.
10+
The `HandlerStack` checks if a request has already been saved and if not,
11+
the request will be sent to the correct host and then the response will be cached,
12+
so that the next time a request will be sent to the API mock, and the cached response will be returned.
13+
14+
```php
15+
<?php
16+
//...
17+
$apiMockClient = new \GuzzleHttp\Client([/*...*/]);
18+
$apiMock = new \ApiMock\Core\ApiMock($apiMockClient);
19+
$proxyStack = new \ApiMock\Proxy\ProxyStack($apiMock);
20+
21+
$myDefaultClient = new \GuzzleHttp\Client([
22+
/*...*/
23+
'handler' => $proxyStack,
24+
]);
25+
26+
// Will be sent against example.org
27+
$myDefaultClient->get('https://example.org', []);
28+
// Will be sent against API Mock
29+
$myDefaultClient->get('https://example.org', []);
30+
```
31+
32+
733
## <a id="Troubleshooting" href="#Troubleshooting">Troubleshooting</a>
834
---
935
#### I used a requestKey, but the `ApiMock::getClientRequest()` gets a 404/null

0 commit comments

Comments
 (0)