-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[HttpClient] Add UriTemplateHttpClient
#49302
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
[HttpClient] Add UriTemplateHttpClient
#49302
Conversation
src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php
Outdated
Show resolved
Hide resolved
src/Symfony/Component/HttpClient/UriTemplate/CallbackUriTemplateExpander.php
Outdated
Show resolved
Hide resolved
202fd20
to
8f69ae0
Compare
global variables / UriTemplateHttpClient feels kinda weird to me, compared to |
UriTemplateHttpClient
src/Symfony/Component/HttpClient/UriTemplate/CallbackUriTemplateExpander.php
Outdated
Show resolved
Hide resolved
src/Symfony/Component/HttpClient/UriTemplate/CallbackUriTemplateExpander.php
Outdated
Show resolved
Hide resolved
d638788
to
3568519
Compare
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.
much simpler :)
src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php
Outdated
Show resolved
Hide resolved
src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php
Outdated
Show resolved
Hide resolved
786db29
to
17d6368
Compare
src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php
Outdated
Show resolved
Hide resolved
17d6368
to
82c4133
Compare
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.
LGTM thanks, just some minor things.
src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php
Outdated
Show resolved
Hide resolved
src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php
Outdated
Show resolved
Hide resolved
src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php
Outdated
Show resolved
Hide resolved
src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php
Outdated
Show resolved
Hide resolved
src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php
Outdated
Show resolved
Hide resolved
bdda79f
to
5e90fc9
Compare
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.
LGTM thanks (decoration issue can be dealt with separately in #49513)
5e90fc9
to
d62d9b9
Compare
Thank you @fancyweb. |
d62d9b9
to
803a54e
Compare
…ation strategy (fancyweb) This PR was merged into the 6.3 branch. Discussion ---------- [FrameworkBundle][HttpClient] Refactor http_client decoration strategy | Q | A | ------------- | --- | Branch? | 6.3 | Bug fix? | no | New feature? | no | Deprecations? | no | Tickets | #49302 (comment) | License | MIT | Doc PR | - Commits ------- 11e2164 [FrameworkBundle][HttpClient] Refactor http_client decoration strategy
…ation strategy (fancyweb) This PR was merged into the 6.3 branch. Discussion ---------- [FrameworkBundle][HttpClient] Refactor http_client decoration strategy | Q | A | ------------- | --- | Branch? | 6.3 | Bug fix? | no | New feature? | no | Deprecations? | no | Tickets | symfony/symfony#49302 (comment) | License | MIT | Doc PR | - Commits ------- 11e2164ee5 [FrameworkBundle][HttpClient] Refactor http_client decoration strategy
…s into single-method interfaces (nicolas-grekas) This PR was merged into the 6.3 branch. Discussion ---------- [DependencyInjection] Add support for casting callables into single-method interfaces | Q | A | ------------- | --- | Branch? | 6.3 | Bug fix? | no | New feature? | yes | Deprecations? | no | Tickets | - | License | MIT | Doc PR | - This PR makes it possible to cast closures to single-method interfaces. It is best reviewed [ignoring whitespaces](https://github.com/symfony/symfony/pull/49632/files?w=1). This works at the service definition level. Here is an example that creates heterogeneous URI-template expanders and exposes them under a common interface (using real classes inspired from #49302): ```php interface UriExpanderInterface { public function expand(string $url, array $vars): string; } ``` And then, in some service configuration using the PHP-DSL: ```php ->set('uri_expander.guzzle', UriExpanderInterface::class) ->fromCallable([\GuzzleHttp\UriTemplate\UriTemplate::class, 'expand']) ->set('uri_template_expander.rize', UriExpanderInterface::class) ->fromCallable([inline_service(\Rize\UriTemplate::class), 'expand']) ->alias(UriExpanderInterface::class, 'uri_template_expander.rize' or 'uri_template_expander.guzzle') ``` Internally, this creates a proxy class that will behave like this one (which could be used in a test case): ```php $expander = new class ($closure) implements UriExpanderInterface { public function __construct(private \Closure $closure) { } public function expand(string $url, array $vars): string { return $this->closure->__invoke($url, $vars); } }; ``` This also adds support for YAML and XML of course: ```yaml services: uri_template_expander.rize: class: UriExpanderInterface from_callable: [ !service {class: Rize\UriTemplate}, expand ] ``` ```xml <services> <service id="uri_template_expander.rize" class="UriExpanderInterface"> <from-callable method="expand"> <service class="Rize\UriTemplate"/> </from-callable> </service> </services> ``` This also works using attributes: ```php class MyClass { public function __construct( #[AutowireCallable([\GuzzleHttp\UriTemplate\UriTemplate::class, 'expand'])] UriExpanderInterface $expander, ) } ``` Commits ------- 9975de2 [DependencyInjection] Make it possible to cast callables into single-method interfaces
…ation strategy (fancyweb) This PR was merged into the 6.3 branch. Discussion ---------- [FrameworkBundle][HttpClient] Refactor http_client decoration strategy | Q | A | ------------- | --- | Branch? | 6.3 | Bug fix? | no | New feature? | no | Deprecations? | no | Tickets | symfony/symfony#49302 (comment) | License | MIT | Doc PR | - Commits ------- 11e2164ee5 [FrameworkBundle][HttpClient] Refactor http_client decoration strategy
This PR adds
UriTemplateHttpClient
to ease using URI templates (see https://www.rfc-editor.org/rfc/rfc6570) withsymfony/http-client
.The goal is not to reimplement the RFC 6570 but to provide a better DX. A vendor has to be installed to expand the urls and we do not impose which one.
The simple usage is:
In a full framework context, all HTTP clients are decorated by
UriTemplateHttpClient
. The support is transparent and enabled globally.It's possible to configure a custom expander by redefining the
http_client.uri_template_expander
alias.