Laravel Http Curl Get Request Example
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...
Hardik Savani
I'm a full-stack developer, entrepreneur and owner of ItSolutionstuff.com. I live in India and I love to write tutorials and tips that can help to other artisan. I am a big fan of PHP, Laravel, Angular, Vue, Node, Javascript, JQuery, Codeigniter and Bootstrap from the early stage. I believe in Hardworking and Consistency.
We are Recommending you
- How to Get Current User Location in Laravel?
- How to Add Country List in Laravel?
- How to Select Custom Column with Value in Laravel Query?
- PHP Curl Request With Bearer Token Authorization Header Example
- PHP Curl PUT Request Example Code
- Laravel Custom Email Verification System Example
- Laravel 8 Model Observers Tutorial Example
- How to use Model Events in Laravel 8?
- Laravel 8 Autocomplete Search from Database Example
- Laravel 8 Resource Route and Controller Tutorial Example
- Laravel CURL Request Example using Ixudra/curl
- PHP Download File from URL using CURL Request Example