Consume 3rd Party API in Laravel

$client = new Client(); //GuzzleHttp\Client
$url = http://dummy.restapiexample.com/api/v1/;
$api_url = $url . 'employees' ;
$params = [
//If you have any Params Pass here
];

$headers = ""; //Ususall pass API Tokens or AUTH Credentials

$response = $client->request ('GET', $api_url, [
//'debug' => config('app.env') !== 'production',
'json' => $params,
'headers' => $headers
]);

return json_decode ((string)$response->getBody ());
  • You’ll get like this
[
{
id: "67785",
employee_name: "z2nep8533222",
employee_salary: "75",
employee_age: "28",
profile_image: ""
},
{
id: "67788",
employee_name: "qem9jm",
employee_salary: "75",
employee_age: "28",
profile_image: ""
},
{
id: "67789",
employee_name: "38rufm",
employee_salary: "75",
employee_age: "28",
profile_image: ""
},
{
id: "67790",
employee_name: "b1rr29",
employee_salary: "75",
employee_age: "28",
profile_image: ""
},
{
id: "67791",
employee_name: "16738w",
employee_salary: "75",
employee_age: "28",
profile_image: ""
},
{
id: "67792",
employee_name: "e0vss",
employee_salary: "75",
employee_age: "28",
profile_image: ""
},
{
id: "67794",
employee_name: "sinta pais ",
employee_salary: "12340",
employee_age: "31",
profile_image: ""
},
. . . . . . . . .. . ......
]

--

--

--

Love podcasts or audiobooks? Learn on the go with our new app.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
sandeep k

sandeep k

More from Medium

Migration From an Existing Database(2) | Laravel

Mastering Sluggable Package in Laravel

Setup Redis on Laravel project 💡

Laravel 8: how to customize the redirect according to the role of the registering user with Fortify