63946: Add "resolvable" routes for the REST API#11606
63946: Add "resolvable" routes for the REST API#11606rmccue wants to merge 6 commits intoWordPress:trunkfrom
Conversation
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the Core Committers: Use this line as a base for the props when committing in SVN: To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
Test using WordPress PlaygroundThe changes in this pull request can previewed and tested using a WordPress Playground instance. WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser. Some things to be aware of
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
|
(cc @prettyboymp @kraftbj for feedback too, as an alternative to #10080) |
|
Love the ergonomics of this approach 👍 |
|
On first glance, these two approaches seem complementary rather than competing, as they tackle 63946 at different layers of the stack. #10080 defers at the namespace boundary: register_rest_route() never runs for a namespace that isn't matched, which also sidesteps whatever REST-only setup plugins put alongside registration — controller instantiation, This one defers at the options boundary: The two stack nicely. We could register a lazy namespace via #10080, and in the action that loads it, use resolvable options for any routes with expensive schemas that might still not be the one hit. Skip the namespace entirely, then if the namespace is hit, skip option construction for non-dispatched routes, and then only fully resolve the actually matched route. tl;dr: :why-not-both.gif: |
Adds the ability to register just-in-time resolvable routes for the REST API.
When calling
register_rest_route(), you can now pass a function instead of the options for the route directly:This has the benefit that any more expensive operations (translations, args-to-schema building, etc) are only run for matched routes, rather than all of them. But, routing is still possible without this (including listing all available namespaces).
Trac ticket: https://core.trac.wordpress.org/ticket/63946
See also #10080
This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.