Introducing the new HTTP Client in Laravel
Laravel has introduced a new HTTP Client comes built-in with Laravel v7, It's built on top of Guzzle HTTP Client. In this short tutorial, we'll check out how this works out of the box in our Laravel apps.
Laravel’s wrapper around Guzzle is focused on its most common use cases and a wonderful developer experience. For example, the client makes it a breeze to POST and interface with JSON data:
use Illuminate\Support\Facades\Http; $response = Http::withHeaders([ 'Authentication' => 'Bearer $token' ])->post('http://test.com/users', [ 'email' => 'email@example.com', ]); return $response['id'];
$response = Http::get($url); $response = Http::get($url,['email'=>'firstname.lastname@example.org']);
Now with new HTTP Client, its even easier in getting responses instead of
json_decode and then retrieving the body as we used to in
$response['email'] $response->body() $response->json() $response->status() $response->ok()