Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

aleksov's avatar

How to use CURL with php

I need help with curl and php...

In API which I need to use I have example of CURL request:

curl https://api.example.com/api/AvailabilitySearch ^ -H "Authorization: Bearer eyJ0ehsagdasjhgdashdgaOiJIUzI1NiJ9.eyJpc3Msjhdshjdasd7676N5c3RlbXMuY29tIn0.DBR5UPxxxxxxzxzxzxzxzxzxzxyzxyzxyzxyzyxzyxyzxyxxWQ_BkS1mzxw" ^ -d VisitDate=2017-05-08 ^ -d PartySize=2 ^ -d ChannelCode=ONLINE

How to make this curl request in php?

0 likes
5 replies
martinbean's avatar

@aleksov PHP has a built-in cURL extension. It’s recommended to use a library like Guzzle though to make HTTP requests instead though.

aleksov's avatar

Ok. How I can query from above run in Laravel with Guzzle ?

martinbean's avatar
Level 80

@aleksov The Guzzle docs show you how to create and send requests. The above would look something like:

$client = new GuzzleHttp\Client;

$response = $client->get('https://api.example.com/api/AvailabilitySearch', [
    'headers' => [
        'Authorization' => 'Bearer YOUR_TOKEN_HERE',
    ],
    'form_params' => [
        'VisitDate' => '2017-05-08',
        'PartySize' => '2',
        'ChannelCode' => 'ONLINE',
    ],
]);

// You need to parse the response body
// This will parse it into an array
$response = json_decode($response->getBody(), true);
9 likes

Please or to participate in this conversation.