I am going to show you example of laravel 8 http client request example. let’s discuss about laravel 8 guzzle http client example. you will learn php laravel 8 http client request. you’ll learn laravel 8 http Client post request.

Laravel 8 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:

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

<?php

use Illuminate\Support\Facades\Route;

use App\Http\Controllers\PostController;

/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/

Route::get('posts', [PostController::class, '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);
    }
}

#laravel #php #web-development #programming #developer

Laravel 8 Guzzle Http Client Request Example
8.15 GEEK