Skip to content

Commit 41d74b9

Browse files
Merge pull request #3 from surplex/feature/Add_proxy_middleware
Feature/add proxy middleware
2 parents 632b072 + 8c00e29 commit 41d74b9

File tree

7 files changed

+999
-443
lines changed

7 files changed

+999
-443
lines changed

.editorconfig

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
root = true
2+
3+
[*]
4+
charset = utf-8
5+
end_of_line = lf
6+
7+
[*.php]
8+
indent_size = 4
9+
indent_style = space
10+
insert_final_newline = true

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

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
}
1111
],
1212
"require": {
13-
"php": ">=7.1",
13+
"php": ">=7.4",
1414
"guzzlehttp/guzzle": "^6.3",
1515
"ext-json": "*"
1616
},

0 commit comments

Comments
 (0)