Skip to content

[HttpClient] Clarifying how to autowire scoped HTTP clients #15330

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

Merged
merged 1 commit into from
May 20, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions http_client.rst
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ autoconfigure the HTTP client based on the requested URL:
http_client:
scoped_clients:
# only requests matching scope will use these options
github:
github.client:
Copy link
Contributor

Choose a reason for hiding this comment

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

github_client:

Works the same 👍🏻

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@OskarStark I'm not sure what you mean? Do you think I should rename all github.client as github_client? What is the point?

Copy link
Contributor

Choose a reason for hiding this comment

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

I see yaml keys more often with underscores. Sure github.client works fine, not sure what to promote

cc @nicolas-grekas

scope: 'https://api\.github\.com'
headers:
Accept: 'application/vnd.github.v3+json'
Expand All @@ -224,7 +224,7 @@ autoconfigure the HTTP client based on the requested URL:

# using base_uri, relative URLs (e.g. request("GET", "/repos/symfony/symfony-docs"))
# will default to these options
github:
github.client:
base_uri: 'https://api.github.com'
headers:
Accept: 'application/vnd.github.v3+json'
Expand All @@ -245,7 +245,7 @@ autoconfigure the HTTP client based on the requested URL:
<framework:config>
<framework:http-client>
<!-- only requests matching scope will use these options -->
<framework:scoped-client name="github"
<framework:scoped-client name="github.client"
scope="https://api\.github\.com"
>
<framework:header name="Accept">application/vnd.github.v3+json</framework:header>
Expand All @@ -254,7 +254,7 @@ autoconfigure the HTTP client based on the requested URL:

<!-- using base-uri, relative URLs (e.g. request("GET", "/repos/symfony/symfony-docs"))
will default to these options -->
<framework:scoped-client name="github"
<framework:scoped-client name="github.client"
base-uri="https://api.github.com"
>
<framework:header name="Accept">application/vnd.github.v3+json</framework:header>
Expand All @@ -271,7 +271,7 @@ autoconfigure the HTTP client based on the requested URL:
'http_client' => [
'scoped_clients' => [
// only requests matching scope will use these options
'github' => [
'github.client' => [
'scope' => 'https://api\.github\.com',
'headers' => [
'Accept' => 'application/vnd.github.v3+json',
Expand All @@ -282,7 +282,7 @@ autoconfigure the HTTP client based on the requested URL:

// using base_url, relative URLs (e.g. request("GET", "/repos/symfony/symfony-docs"))
// will default to these options
'github' => [
'github.client' => [
'base_uri' => 'https://api.github.com',
'headers' => [
'Accept' => 'application/vnd.github.v3+json',
Expand Down Expand Up @@ -329,8 +329,8 @@ Each client has a unique service named after its configuration.

Each scoped client also defines a corresponding named autowiring alias.
If you use for example
``Symfony\Contracts\HttpClient\HttpClientInterface $myApiClient``
as the type and name of an argument, autowiring will inject the ``my_api.client``
``Symfony\Contracts\HttpClient\HttpClientInterface $githubClient``
as the type and name of an argument, autowiring will inject the ``github.client``
service into your autowired classes.

.. note::
Expand Down