Skip to content

Commit b24772f

Browse files
[8.x]: improve http client docs (laravel#7659)
* [8.x]: improve http client docs * Update http-client.md * Update http-client.md Co-authored-by: Taylor Otwell <[email protected]>
1 parent e4502c3 commit b24772f

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

http-client.md

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ Before getting started, you should ensure that you have installed the Guzzle pac
2828
<a name="making-requests"></a>
2929
## Making Requests
3030

31-
To make requests, you may use the `get`, `post`, `put`, `patch`, and `delete` methods provided by the `Http` facade. First, let's examine how to make a basic `GET` request to another URL:
31+
To make requests, you may use the `head`, `get`, `post`, `put`, `patch`, and `delete` methods provided by the `Http` facade. First, let's examine how to make a basic `GET` request to another URL:
3232

3333
use Illuminate\Support\Facades\Http;
3434

@@ -37,12 +37,13 @@ To make requests, you may use the `get`, `post`, `put`, `patch`, and `delete` me
3737
The `get` method returns an instance of `Illuminate\Http\Client\Response`, which provides a variety of methods that may be used to inspect the response:
3838

3939
$response->body() : string;
40-
$response->json() : array|mixed;
40+
$response->json($key = null) : array|mixed;
4141
$response->object() : object;
42-
$response->collect() : Illuminate\Support\Collection;
42+
$response->collect($key = null) : Illuminate\Support\Collection;
4343
$response->status() : int;
4444
$response->ok() : bool;
4545
$response->successful() : bool;
46+
$response->redirect(): bool;
4647
$response->failed() : bool;
4748
$response->serverError() : bool;
4849
$response->clientError() : bool;
@@ -197,6 +198,9 @@ Unlike Guzzle's default behavior, Laravel's HTTP client wrapper does not throw e
197198
// Determine if the response has a 500 level status code...
198199
$response->serverError();
199200

201+
// Immediately execute the given callback if there was a client or server error...
202+
$response->onError(callable $callback);
203+
200204
<a name="throwing-exceptions"></a>
201205
#### Throwing Exceptions
202206

@@ -416,6 +420,12 @@ If needed, you may assert that a specific request was not sent using the `assert
416420
return $request->url() === 'http://example.com/posts';
417421
});
418422

423+
You may use the `assertSentCount` method to assert how many requests were "sent" during the test:
424+
425+
Http::fake();
426+
427+
Http::assertSentCount(5);
428+
419429
Or, you may use the `assertNothingSent` method to assert that no requests were sent during the test:
420430

421431
Http::fake();

0 commit comments

Comments
 (0)