Skip to content

Instantly share code, notes, and snippets.

@Stormix
Created July 18, 2017 18:33
Show Gist options
  • Save Stormix/92653dfd13932e9c8aa5c4dfa801b1fa to your computer and use it in GitHub Desktop.
Save Stormix/92653dfd13932e9c8aa5c4dfa801b1fa to your computer and use it in GitHub Desktop.
<?php
$client = new \GuzzleHttp\Client();
$res = $client->request('GET', 'https://api.github.com/repos/guzzle/guzzle');
echo $res->getStatusCode();
// 200
echo $res->getHeaderLine('content-type');
// 'application/json; charset=utf8'
echo $res->getBody();
// '{"id": 1420053, "name": "guzzle", ...}'
// Send an asynchronous request.
$request = new \GuzzleHttp\Psr7\Request('GET', 'http://httpbin.org');
$promise = $client->sendAsync($request)->then(function ($response) {
echo 'I completed! ' . $response->getBody();
});
$promise->wait();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment