Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve examples #1

Merged
merged 1 commit into from Aug 17, 2019

Conversation

@nicolas-grekas
Copy link
Contributor

commented Aug 11, 2019

No description provided.

@nicolas-grekas
Copy link
Contributor Author

left a comment

The added comments highlight a major difference: reading the responses can happen in network order when using the Symfony client. (and you can also have access to individual chunks of incoming data, but none of your examples are about that so it's a bit off-topic.)

$responses = [];
foreach ($delays as $offset => $delay) {
try {
$responses[] = $this->httpClient->request(

This comment has been minimized.

Copy link
@nicolas-grekas

nicolas-grekas Aug 11, 2019

Author Contributor

the request method is lazy: it should do no network, no need to wrap it in a try/catch

if ($chunk->isLast()) {
$jsons[$response->getInfo('url')] = $response->toArray();
}
} catch (TransportExceptionInterface $transportException) {

This comment has been minimized.

Copy link
@nicolas-grekas

nicolas-grekas Aug 11, 2019

Author Contributor

chunks do throw instead

'GET',
sprintf('https://reqres.in/api/users/%d?delay=%d', $offset + 1, $delay)
);
$data = $response->toArray();

This comment has been minimized.

Copy link
@nicolas-grekas

nicolas-grekas Aug 11, 2019

Author Contributor

responses throw, not the request method (unless one is using a non-lazy implementation, but hey don't use any of them if one exists :) )

@nicolas-grekas nicolas-grekas force-pushed the nicolas-grekas:http_client branch from 8ae02d0 to ac3f4e0 Aug 12, 2019

@dbrumann
Copy link
Owner

left a comment

Thanks for the improvement and the explanations

@dbrumann dbrumann merged commit 96a31e7 into dbrumann:http_client Aug 17, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.