---
description: >-
  https://www.itsolutionstuff.com/post/laravel-7-http-client-request-laravel-7-guzzle-http-client-exampleexample.html
---

# Laravel 7 Http Client Request | Laravel 7 Guzzle Http Client Example

## Laravel 7 Http Client Request | Laravel 7 Guzzle Http Client Example

By Hardik Savani March 13, 2020 Category : Laravel![](https://a.vdo.ai/core/assets/img/cross.svg)PlayUnmuteLoaded: 1.15%Fullscreen[![VDO.AI](https://a.vdo.ai/core/assets/img/logo.svg)](https://vdo.ai/?utm_medium=video\&utm_term=itsolutionstuff.com\&utm_source=vdoai_logo)In this quick example, let's see laravel 7 guzzle http client example. you will learn laravel 7 http client request. This tutorial will give you simple example of http curl request in laravel 7. it's simple example of laravel 7 HTTP Client post.

Laravel 7 provide inbuilt HTTP Client using guzzlehttp/guzzle package. you can easily run http client request using Http facade. you can send GET, POST, PUT, DELETE request with you can easily get response with text and json too. you can also pass header and authentication token easily.

Here, i will give you very simple example with output. you can see bellow example so you can easily understand how it works:

![](https://www.itsolutionstuff.com/upload/laravel-7-http-client.png)

**Install guzzlehttp/guzzle**

Here, we will install guzzlehttp/guzzle composer package. we must have to install this package for execute http client request. so let's run bellow command:

```
composer require guzzlehttp/guzzle
```

**Simple Example:**

We will create very simple http request full example. we need to create simple route to call controller method. so let's create it:

routes/web.php

```
Route::get('posts','PostController@index');
```

app/Http/Controllers/PostController.php

```
<?php  namespace App\Http\Controllers;  use Illuminate\Http\Request;use Illuminate\Support\Facades\Http; class PostController extends Controller{    public function index()    {    	$response = Http::get('http://jsonplaceholder.typicode.com/posts');      	$jsonData = $response->json();      	     	dd($jsonData);    }}
```

Output:

![](https://www.itsolutionstuff.com/upload/laravel-7-http-client-2.png)

**Http Post Request Example:**

We will create very simple http request full example. we need to create simple route to call controller method. so let's create it:

routes/web.php

```
Route::get('posts/store','PostController@store');
```

app/Http/Controllers/PostController.php

```
<?php  namespace App\Http\Controllers;  use Illuminate\Http\Request;use Illuminate\Support\Facades\Http;   class PostController extends Controller{       public function store()    {    	$response = Http::post('http://jsonplaceholder.typicode.com/posts', [    				'title' => 'This is test from ItSolutionStuff.com',    				'body' => 'This is test from ItSolutionStuff.com as body',    			]);      	dd($response->successful());    }}
```

**Example with Response:**

We will create very simple http request full example. we need to create simple route to call controller method. so let's create it:

routes/web.php

[![](https://go.ezodn.com/charity/http/charity-ads.s3.amazonaws.com/charity_ads/1079/300x250.png)](https://go.ezodn.com/ads/charity/proxy?p_id=a259490c-a7be-45aa-69ee-6cd7ecba23b1\&d_id=77568\&imp_id=4760985556801677\&c_id=1079\&l_id=10016\&url=https%3A%2F%2Fwww.directrelief.org%2Femergency%2Fukraine-crisis%2F\&ffid=1\&co=VN)[![](https://go.ezodn.com/charity/http/charity-ads.s3.amazonaws.com/charity_ads/1079/300x250.png)](https://go.ezodn.com/ads/charity/proxy?p_id=a259490c-a7be-45aa-69ee-6cd7ecba23b1\&d_id=77568\&imp_id=4760985556801677\&c_id=1079\&l_id=10016\&url=https%3A%2F%2Fwww.directrelief.org%2Femergency%2Fukraine-crisis%2F\&ffid=1\&co=VN)[![](https://go.ezodn.com/charity/http/charity-ads.s3.amazonaws.com/charity_ads/1093/300x250.png)](https://go.ezodn.com/ads/charity/proxy?p_id=a259490c-a7be-45aa-69ee-6cd7ecba23b1\&d_id=77568\&imp_id=4760985556801677\&c_id=1093\&l_id=10016\&url=https%3A%2F%2Fwww.directrelief.org%2Femergency%2Fukraine-crisis%2F\&ffid=1\&co=VN)

```
Route::get('posts','PostController@index');
```

app/Http/Controllers/PostController.php

```
<?php  namespace App\Http\Controllers;  use Illuminate\Http\Request;use Illuminate\Support\Facades\Http; class PostController extends Controller{    public function index()    {    	$response = Http::get('http://jsonplaceholder.typicode.com/posts');      	$jsonData = $response->json();    	      	echo "<pre> status:";    	print_r($response->status());    	echo "<br/> ok:";    	print_r($response->ok());        echo "<br/> successful:";        print_r($response->successful());        echo "<br/> serverError:";        print_r($response->serverError());        echo "<br/> clientError:";        print_r($response->clientError());        echo "<br/> headers:";        print_r($response->headers());    }}
```

Output:

Read Also: [Laravel 7 Database Seeder Example](https://www.itsolutionstuff.com/post/laravel-7-database-seeder-exampleexample.html)

```
 status:200 ok:1 successful:1 serverError: clientError: headers:Array(    [Date] => Array        (            [0] => Thu, 12 Mar 2020 06:08:58 GMT        )    [Content-Type] => Array        (            [0] => application/json; charset=utf-8        )    [Transfer-Encoding] => Array        (            [0] => chunked        )    .....)
```

You can also get more information about Http Client in Laravel Docs: [Click Here](https://laravel.com/docs/7.x/http-client).

I hope it can help you...
