-
-
Notifications
You must be signed in to change notification settings - Fork 84
Add "Making HTTP requests" cookbook article with Guzzle and PSR interface examples #247
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
Add "Making HTTP requests" cookbook article with Guzzle and PSR interface examples #247
Conversation
…terface examples Co-authored-by: samdark <[email protected]>
Co-authored-by: samdark <[email protected]>
cookbook/en and cookbook/en/README.md named "Making HTTP requests" where an example is given of using Guzzle to make an HTTP request. All the code examples should use PSR interfaces.
cookbook/en/making-http-requests.md
Outdated
| Install the Guzzle HTTP client with PSR-18 support: | ||
|
|
||
| ```shell | ||
| composer require guzzlehttp/guzzle --prefer-dist |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| composer require guzzlehttp/guzzle --prefer-dist | |
| composer require guzzlehttp/guzzle |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed - removed --prefer-dist from composer command. (d35a971)
cookbook/en/making-http-requests.md
Outdated
| @@ -0,0 +1,367 @@ | |||
| # Making HTTP requests | |||
|
|
|||
| When building modern web applications, you often need to make HTTP requests to external APIs, microservices, or third-party services. This article demonstrates how to make HTTP requests in Yii3 applications using Guzzle with PSR (PHP Standards Recommendations) interfaces. | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| When building modern web applications, you often need to make HTTP requests to external APIs, microservices, or third-party services. This article demonstrates how to make HTTP requests in Yii3 applications using Guzzle with PSR (PHP Standards Recommendations) interfaces. | |
| When building modern applications, you often need to make HTTP requests to external APIs. This article demonstrates how to make HTTP requests in Yii3 applications using Guzzle with and [PSR interfaces](https://www.php-fig.org/psr/). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated the opening sentence with proper formatting and PSR link. (d35a971)
cookbook/en/making-http-requests.md
Outdated
| For creating PSR-7 requests and responses manually, you can install PSR-17 factories: | ||
|
|
||
| ```shell | ||
| composer require guzzlehttp/psr7 --prefer-dist |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| composer require guzzlehttp/psr7 --prefer-dist | |
| composer require guzzlehttp/psr7 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed --prefer-dist from the PSR7 installation command. (d35a971)
cookbook/en/making-http-requests.md
Outdated
| composer require guzzlehttp/guzzle --prefer-dist | ||
| ``` | ||
|
|
||
| ### Install PSR factories (optional) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not optional for our examples. Do in the same step as guzzle itself.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Merged installation steps - PSR7 is now installed together with Guzzle in the same section since it's required for the examples. (d35a971)
cookbook/en/making-http-requests.md
Outdated
| $jsonData = json_encode($userData, JSON_THROW_ON_ERROR); | ||
| $stream = $this->streamFactory->createStream($jsonData); | ||
|
|
||
| $request = $this->requestFactory->createRequest('POST', 'https://jsonplaceholder.typicode.com/users') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use example.com instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed to example.com. (d35a971)
cookbook/en/making-http-requests.md
Outdated
| RequestFactoryInterface::class => HttpFactory::class, | ||
| ResponseFactoryInterface::class => HttpFactory::class, | ||
| StreamFactoryInterface::class => HttpFactory::class, | ||
| UriFactoryInterface::class => HttpFactory::class, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is problematic since there could be non-guzzle implementation of PSR-7 used already. Is there a better way?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated DI configuration to use factory functions instead of direct class references, making it clear which PSR-7 implementation is being used and allowing easier switching between implementations. (d35a971)
cookbook/en/making-http-requests.md
Outdated
| RequestFactoryInterface::class => HttpFactory::class, | ||
| ResponseFactoryInterface::class => HttpFactory::class, | ||
| StreamFactoryInterface::class => HttpFactory::class, | ||
| UriFactoryInterface::class => HttpFactory::class, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is problematic since there could be non-guzzle implementation of PSR-7 used already. Is there a better way?
cookbook/en/making-http-requests.md
Outdated
|
|
||
| foreach ($userIds as $userId) { | ||
| $promises[$userId] = $this->httpClient->getAsync( | ||
| "https://jsonplaceholder.typicode.com/users/{$userId}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use example.com
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed to example.com. (d35a971)
| return $results; | ||
| } | ||
| } | ||
| ``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a note that this feature isn't part of PSR interfaces, so the code will depend on Guzzle explicitly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added a note explaining that async functionality isn't part of PSR interfaces and requires Guzzle explicitly. (d35a971)
|
@copilot please fix comments. |
…, use example.com, improve DI configuration Co-authored-by: samdark <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds a new cookbook article that demonstrates how to make HTTP requests in Yii3 applications using Guzzle and PSR standard interfaces. The article provides practical examples and best practices for HTTP client implementation.
Key changes:
- New comprehensive cookbook article covering HTTP requests with Guzzle
- Documentation of PSR-7, PSR-17, and PSR-18 interface usage
- Code examples for GET/POST requests, error handling, middleware, async operations, and testing
Reviewed Changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| cookbook/en/making-http-requests.md | New article with HTTP request examples using Guzzle and PSR interfaces |
| cookbook/en/README.md | Added link to new HTTP requests article |
| cookbook/ru/README.md | Added link placeholder for Russian translation |
| _translations/cookbook/pot/README.md.pot | Updated translation template with new entry |
| _translations/cookbook/po/ru/README.md.po | Updated Russian translation file with untranslated entry |
| @@ -0,0 +1,367 @@ | |||
| # Making HTTP requests | |||
|
|
|||
| When building modern applications, you often need to make HTTP requests to external APIs. This article demonstrates how to make HTTP requests in Yii3 applications using Guzzle with and [PSR interfaces](https://www.php-fig.org/psr/). | |||
Copilot
AI
Oct 19, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Corrected grammar by removing 'with and' and replacing with 'and'.
| When building modern applications, you often need to make HTTP requests to external APIs. This article demonstrates how to make HTTP requests in Yii3 applications using Guzzle with and [PSR interfaces](https://www.php-fig.org/psr/). | |
| When building modern applications, you often need to make HTTP requests to external APIs. This article demonstrates how to make HTTP requests in Yii3 applications using Guzzle and [PSR interfaces](https://www.php-fig.org/psr/). |
💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.