Laravel / Controller / Connecting external APIs using http client
HTTP Client
-
STEP
Step 1: Install Guzzle package
composer require guzzlehttp/guzzle get() method
$client = new \GuzzleHttp\Client(); $request = $client->get('http://example.com');// Url of your choosing $response = $request->getBody(); dd($response); post() method
$client = new \GuzzleHttp\Client(); $url = "http://example.com/api/posts"; $data['name'] = "LaravelCode"; $request = $client->post($url, ['body'=>$data]); $response = $request->send(); dd($response); POST with json data
$param['name'] ="mmm"; $response = Http::withBody(json_encode($param),'application/json') ->withHeaders([ 'subscriptionkey' => env('FACE_MX_KEY'), ]) ->post(env('FACE_MX_ENDPOINT')); $result=json_decode($response->body());