Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Sep 4, 2025


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

Copilot AI changed the title [WIP] @yiisoft/docs/issues/57 Need to add an article under 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. Add "Making HTTP requests" cookbook article with Guzzle and PSR interface examples Sep 4, 2025
Copilot AI requested a review from samdark September 4, 2025 23:18
Install the Guzzle HTTP client with PSR-18 support:

```shell
composer require guzzlehttp/guzzle --prefer-dist
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
composer require guzzlehttp/guzzle --prefer-dist
composer require guzzlehttp/guzzle

Copy link
Contributor Author

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)

@@ -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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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/).

Copy link
Contributor Author

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)

For creating PSR-7 requests and responses manually, you can install PSR-17 factories:

```shell
composer require guzzlehttp/psr7 --prefer-dist
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
composer require guzzlehttp/psr7 --prefer-dist
composer require guzzlehttp/psr7

Copy link
Contributor Author

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)

composer require guzzlehttp/guzzle --prefer-dist
```

### Install PSR factories (optional)
Copy link
Member

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.

Copy link
Contributor Author

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)

$jsonData = json_encode($userData, JSON_THROW_ON_ERROR);
$stream = $this->streamFactory->createStream($jsonData);

$request = $this->requestFactory->createRequest('POST', 'https://jsonplaceholder.typicode.com/users')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use example.com instead.

Copy link
Contributor Author

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)

Comment on lines 139 to 142
RequestFactoryInterface::class => HttpFactory::class,
ResponseFactoryInterface::class => HttpFactory::class,
StreamFactoryInterface::class => HttpFactory::class,
UriFactoryInterface::class => HttpFactory::class,
Copy link
Member

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?

Copy link
Contributor Author

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)

Comment on lines 139 to 142
RequestFactoryInterface::class => HttpFactory::class,
ResponseFactoryInterface::class => HttpFactory::class,
StreamFactoryInterface::class => HttpFactory::class,
UriFactoryInterface::class => HttpFactory::class,
Copy link
Member

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?


foreach ($userIds as $userId) {
$promises[$userId] = $this->httpClient->getAsync(
"https://jsonplaceholder.typicode.com/users/{$userId}"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use example.com

Copy link
Contributor Author

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;
}
}
```
Copy link
Member

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.

Copy link
Contributor Author

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)

@samdark
Copy link
Member

samdark commented Sep 4, 2025

@copilot please fix comments.

…, use example.com, improve DI configuration

Co-authored-by: samdark <[email protected]>
Copy link
Contributor Author

Copilot AI commented Sep 4, 2025

@copilot please fix comments.

All review comments have been addressed in commit d35a971. The article now uses proper composer commands, correct PSR ordering, example.com URLs, improved DI configuration, and includes necessary clarifications about Guzzle-specific features.

Copilot AI requested a review from samdark September 4, 2025 23:40
@samdark samdark marked this pull request as ready for review October 19, 2025 11:35
Copilot AI review requested due to automatic review settings October 19, 2025 11:35
@samdark samdark merged commit 50d2394 into master Oct 19, 2025
8 checks passed
@samdark samdark deleted the copilot/fix-07b1bda4-2546-43ad-b39f-04c17bec3ea9 branch October 19, 2025 11:35
Copy link
Contributor

Copilot AI left a 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/).
Copy link

Copilot AI Oct 19, 2025

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'.

Suggested change
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/).

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants