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:
Also Read: Laravel Interview Questions
Post Request
use Illuminate\Support\Facades\Http;
$response = Http::withHeaders([
'Authentication' => 'Bearer $token'
])->post('http://test.com/users', [
'email' => '[email protected]',
]);
return $response['id'];
Get Request
$response = Http::get($url);
$response = Http::get($url,['email'=>'[email protected]']);
Responses
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 GuzzleHTTP.
$response['email']
$response->body()
$response->json()
$response->status()
$response->ok()