1

I am currently working on a website in which I use PHP. I want to make a get request like the one shown here in Ruby code:

response = RestClient::Request.execute(
:method  => :get,
:url     => 'https://api.place2book.com/event_api/available_tickets',
:timeout => 5,
:headers => {
'X-PLACE2BOOK-API-TOKEN' => 'foobar789baz7674',
'X-PLACE2BOOK-EVENT-ID' => 123456
}
)

response.headers[:available_tickets]

However I do not know much of API Get requests in PHP.

Pholochtairze
  • 1,836
  • 1
  • 14
  • 18
  • you can use curl for that, or use a library for more functionnality like guzzle: http://docs.guzzlephp.org – yoeunes Aug 02 '17 at 09:32

1 Answers1

0

i suggest using guzzle :

http://docs.guzzlephp.org/en/stable/

$client = new GuzzleHttp\Client();
$res = $client->request('GET', 'https://api.github.com/user', [
    'auth' => ['user', 'pass']
]);
echo $res->getStatusCode();
// "200"
echo $res->getHeader('content-type');
// 'application/json; charset=utf8'
echo $res->getBody();
// {"type":"User"...'
yoeunes
  • 2,927
  • 2
  • 15
  • 26