Last active
August 18, 2019 20:08
-
-
Save mosampaio/e9b7dded923b18d3ccf6ee257b503dc8 to your computer and use it in GitHub Desktop.
How to consume a json Rest API with PHP using Guzzle
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"require": { | |
"guzzlehttp/guzzle": "~6.0" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment