Created
December 9, 2019 00:53
-
-
Save kklecho/e21fda565eff47f940e7d5abf14e2659 to your computer and use it in GitHub Desktop.
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
#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