Add query() route method for the HTTP QUERY verb (RFC 10008) - #3461
Add query() route method for the HTTP QUERY verb (RFC 10008)#3461purwantoid wants to merge 4 commits into
Conversation
The HTTP QUERY method was recently published as RFC 10008 on the IETF Standards Track. It is a safe, cacheable method that carries its query in the request body, enabling expressive queries without the URL-length and cacheability trade-offs of GET vs. POST. Support for QUERY is landing across the ecosystem (https://www.rfc-editor.org/rfc/rfc10008), so this adds a query() helper as a sibling of the existing get()/post()/put()/patch()/ delete()/options() route methods on RouteCollectorProxyInter implemented via the existing map() mechanism: ``` $app->query('/search', function (Request $request, Response $response) { $criteria = (string) $request->getBody(); // ...run the query described in the request body... return $response; }); ``` `$app->query()` is equivalent to `$app->map(['QUERY'], ...)` and is not added to any(), so existing any() routes are unaffected.
…owsRuntimeException
|
@akrabat I think we should add the query method for routing, but this would also be a breaking change in RouteCollectorProxyInterface. If we add it, we could use a new minor version (4.16.0). What do you think? |
|
I agree we should support it. Do we have to put it in the interface? Can we use a dockblock for IDE autocomplete? |
|
@akrabat yes, we have add it in the interface. |
What I mean is that changing that interface breaks BC. Therefore we need another solution. Back in 4.2.0, we added |
|
My guess is that we just need as a docbock entry on |
Declare query() as an @method so that we maintain BC.
|
I have pushed my suggestion. |
|
@akrabat thanks. |
Summary
The HTTP
QUERYmethod was recently published as RFC 10008 on the IETF Standards Track. It is a safe, cacheable method that carries its query in the request body, enabling expressive queries without the URL-length and cacheability trade-offs of GET vs. POST. Support forQUERYis landing across the ecosystem, so this adds aquery()helper as a sibling of the existingget()/post()/put()/patch()/delete()/options()route methods.query()toRouteCollectorProxyInterfaceand its implementation inRouteCollectorProxy, equivalent tomap(['QUERY'], $pattern, $callable).any()'s method list, so existingany()routes are unaffected.[Unreleased] / Added.Test plan
vendor/bin/phpunit— full suite passes (437 tests)vendor/bin/phpcs— clean (PSR-12)vendor/bin/phpstan --memory-limit=-1— clean (level max)RouteCollectorProxyTest::testQuery()(unit-level, mirrorstestOptions())AppTest::testQueryRoute()(end-to-end, mirrors the GET/POST/etc. verb test)