@@ -740,7 +740,7 @@ Retry Over Several Base URIs
740
740
741
741
The ``RetryableHttpClient `` can be configured to use multiple base URIs. This
742
742
feature provides increased flexibility and reliability for making HTTP
743
- requests. Pass an array of base URIs as option ``base_uri `` when making a
743
+ requests. Pass an array of base URIs as option ``base_uri `` when making a
744
744
request::
745
745
746
746
$response = $client->request('GET', 'some-page', [
@@ -752,7 +752,7 @@ request::
752
752
],
753
753
]);
754
754
755
- When the number of retries is higher than the number of base URIs, the
755
+ When the number of retries is higher than the number of base URIs, the
756
756
last base URI will be used for the remaining retries.
757
757
758
758
If you want to shuffle the order of base URIs for each retry attempt, nest the
@@ -770,13 +770,13 @@ base URIs you want to shuffle in an additional array::
770
770
],
771
771
]);
772
772
773
- This feature allows for a more randomized approach to handling retries,
773
+ This feature allows for a more randomized approach to handling retries,
774
774
reducing the likelihood of repeatedly hitting the same failed base URI.
775
775
776
- By using a nested array for the base URI, you can use this feature
776
+ By using a nested array for the base URI, you can use this feature
777
777
to distribute the load among many nodes in a cluster of servers.
778
778
779
- You can also configure the array of base URIs using the ``withOptions() ``
779
+ You can also configure the array of base URIs using the ``withOptions() ``
780
780
method::
781
781
782
782
$client = $client->withOptions(['base_uri' => [
@@ -2032,6 +2032,30 @@ Then configure Symfony to use your callback:
2032
2032
;
2033
2033
};
2034
2034
2035
+ To return json, you would normally do::
2036
+
2037
+ use Symfony\Component\HttpClient\Response\MockResponse;
2038
+
2039
+ $response = new MockResponse(json_encode([
2040
+ 'foo' => 'bar',
2041
+ ]), [
2042
+ 'response_headers' => [
2043
+ 'content-type' => 'application/json',
2044
+ ],
2045
+ ]);
2046
+
2047
+ You can use :class: `Symfony\\ Component\\ HttpClient\\ Response\\ JsonMockResponse ` instead::
2048
+
2049
+ use Symfony\Component\HttpClient\Response\JsonMockResponse;
2050
+
2051
+ $response = new JsonMockResponse([
2052
+ 'foo' => 'bar',
2053
+ ]);
2054
+
2055
+ .. versionadded :: 6.3
2056
+
2057
+ The ``JsonMockResponse `` was introduced in Symfony 6.3.
2058
+
2035
2059
Testing Request Data
2036
2060
~~~~~~~~~~~~~~~~~~~~
2037
2061
0 commit comments