Home > Software design >  Best way to fetch api in laravel
Best way to fetch api in laravel

Time:06-01

I want to fetch external api in my project in laravel. what is the best way to fetch api in laravel??

CodePudding user response:

Everything is described in the documentation of Laravel, you can/should use Laravel Http Facade

https://laravel.com/docs/9.x/http-client

CodePudding user response:

You can use the

  1. Curl for the using external apis in laravel project

  2. You can install Guzzle through composer composer require guzzlehttp/guzzle:~6.0

    composer.json

{ "require": { "guzzlehttp/guzzle": "~6.0" } }

//code is here

$client = new GuzzleHttp\Client(); $res = $client->get('https://api.github.com/user', ['auth' => ['user', 'pass']]); echo $res->getStatusCode(); // 200 echo $res->getBody();

  • Related