Support the QUERY HTTP method

Merged
JO
6d ago
+137-1

Adds support for the new QUERY HTTP method (RFC 10008).

Compliments laravel/framework#61797

Routes registered with Route::match(['QUERY'], ...) already generate correctly. However, the Method type in wayfinder.ts doesn't include "query", so the generated RouteDefinition<"query"> fails to type-check. This PR adds "query" to that union.

search(); // { url: "/search", method: "query" }
search.query(); // { url: "/search", method: "query" }
search.form(); // { action: "/search?_method=QUERY", method: "post" }

HTML forms only support GET and POST, so form variants spoof QUERY over POST via _method, just like PUT, PATCH and DELETE. Symfony's Request allows overriding to QUERY; it only blocks GET, HEAD, CONNECT and TRACE.

The generated method is lowercase ("query"), consistent with the other verbs. The Fetch standard doesn't normalise the casing of query (the same is true of patch), so HTTP clients that pass the method straight to fetch may want to uppercase it.

Tests

  • A new SearchController in the workbench, with a QUERY-only route and a GET + QUERY route
  • tests/QueryMethod.test.ts covers definitions, the default method, .query(), named routes and the form variants