Langue:

Recherche

Introducing the new HTTP Client in Laravel

  • Partagez ceci:
Introducing the new HTTP Client in Laravel

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()

Read more about it at the official Laravel Documentation

Mots clés:
Usama Muneer

Usama Muneer

A web enthusiastic, self-motivated & detail-oriented professional Full-Stack Web Developer from Karachi, Pakistan with experience in developing applications using JavaScript, WordPress & Laravel specifically. Loves to write on different web technologies with an equally useful skill to make some sense out of it.

Your experience on this site will be improved by allowing cookies Cookie Policy