Skip to content

Instantly share code, notes, and snippets.

@mosampaio
Last active August 18, 2019 20:08
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save mosampaio/e9b7dded923b18d3ccf6ee257b503dc8 to your computer and use it in GitHub Desktop.
Save mosampaio/e9b7dded923b18d3ccf6ee257b503dc8 to your computer and use it in GitHub Desktop.
How to consume a json Rest API with PHP using Guzzle
<?php
require __DIR__ . '/vendor/autoload.php';
use GuzzleHttp\Client;
$client = new Client([
'base_uri' => 'https://api.github.com',
'timeout' => 5.0,
]);
$response = $client->get('/repos/twilio/twilio-php/contributors');
$body = json_decode($response->getBody());
print_r($body);
{
"require": {
"guzzlehttp/guzzle": "~6.0"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment