Skip to content

Instantly share code, notes, and snippets.

@kklecho
Created December 9, 2019 00:53
Show Gist options
  • Save kklecho/e21fda565eff47f940e7d5abf14e2659 to your computer and use it in GitHub Desktop.
Save kklecho/e21fda565eff47f940e7d5abf14e2659 to your computer and use it in GitHub Desktop.
#install
composer require symfony/http-client
#use
use Symfony\Component\HttpClient\HttpClient;
$client = HttpClient::create();
$response = $client->request('GET', 'https://api.github.com/repos/symfony/symfony-docs');
$statusCode = $response->getStatusCode();
// $statusCode = 200
$contentType = $response->getHeaders()['content-type'][0];
// $contentType = 'application/json'
$content = $response->getContent();
// $content = '{"id":521583, "name":"symfony-docs", ...}'
$content = $response->toArray();
// $content = ['id' => 521583, 'name' => 'symfony-docs', ...]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment