ItSolutionStuff.com

Laravel Http Curl Get Request Example

By Hardik Savani β€’ November 5, 2023
Laravel

This example is focused on laravel http curl get request example. We will look at example of laravel curl get request example. This post will give you simple example of laravel http request get parameters. let’s discuss about how to call curl get request in laravel. Here, Creating a basic example of how to get curl request in php laravel.

Here, i will give you two examples of how to call curl get request with laravel GuzzleHttp. first example will with http and second example with GuzzleHttp. so let's see both examples one by one here.

Install guzzlehttp/guzzle Package:

you have to install guzzlehttp/guzzle composer package in your project:

composer require guzzlehttp/guzzle

Example 1:

<?php

namespace App\Http\Controllers;

use Illuminate\Support\Facades\Http;

class ITSController extends Controller

{

/**

* Write code on Method

*

* @return response()

*/

public function index()

{

$apiURL = 'https://api.mywebtuts.com/api/users';

$parameters = ['page' => 2];

$response = Http::get($apiURL, $parameters);

$statusCode = $response->status();

$responseBody = json_decode($response->getBody(), true);

dd($responseBody);

}

}

Output

Array

(

[current_page] => 2

[data] => Array

(

[0] => Array

(

[id] => 7

[first_name] => Howell

[last_name] => Funke

[email] => howellfunke@gmail.com

[avatar] => https://api.mywebtuts.com/asset/img/photo-7.png

)

[1] => Array

(

[id] => 8

[first_name] => Edwards

[last_name] => Lindsay

[email] => edwardslindsay@gmail.com

[avatar] => https://api.mywebtuts.com/asset/img/photo-9.png

)

...........

...........

Example 2:

<?php

namespace App\Http\Controllers;

class ITSController extends Controller

{

/**

* Write code on Method

*

* @return response()

*/

public function index2()

{

$apiURL = 'https://api.mywebtuts.com/api/users';

$parameters = ['page' => 2];

$client = new \GuzzleHttp\Client();

$response = $client->request('GET', $apiURL, ['query' => $parameters]);

$statusCode = $response->getStatusCode();

$responseBody = json_decode($response->getBody(), true);

dd($responseBody);

}

}

Output

Array

(

[current_page] => 2

[data] => Array

(

[0] => Array

(

[id] => 7

[first_name] => Howell

[last_name] => Funke

[email] => howellfunke@gmail.com

[avatar] => https://api.mywebtuts.com/asset/img/photo-7.png

)

[1] => Array

(

[id] => 8

[first_name] => Edwards

[last_name] => Lindsay

[email] => edwardslindsay@gmail.com

[avatar] => https://api.mywebtuts.com/asset/img/photo-9.png

)

...........

...........

i hope it can help you...

Tags: Laravel
Hardik Savani

Hardik Savani

I'm a full-stack developer, entrepreneur, and founder of ItSolutionStuff.com. Passionate about PHP, Laravel, JavaScript, and helping developers grow.

πŸ“Ί Subscribe on YouTube

We Are Recommending You

β˜…

How to Get Current User Location in Laravel?

Read Now β†’
β˜…

How to Add Country List in Laravel?

Read Now β†’
β˜…

How to Select Custom Column with Value in Laravel Query?

Read Now β†’
β˜…

PHP Curl Request With Bearer Token Authorization Header Example

Read Now β†’
β˜…

PHP Curl PUT Request Example Code

Read Now β†’
β˜…

Laravel Custom Email Verification System Example

Read Now β†’
β˜…

Laravel 8 Model Observers Tutorial Example

Read Now β†’
β˜…

How to use Model Events in Laravel 8?

Read Now β†’
β˜…

Laravel 8 Autocomplete Search from Database Example

Read Now β†’
β˜…

Laravel 8 Resource Route and Controller Tutorial Example

Read Now β†’
β˜…

Laravel CURL Request Example using Ixudra/curl

Read Now β†’
β˜…

PHP Download File from URL using CURL Request Example

Read Now β†’