Closed BenRutlandWeb closed 2 years ago
Whilst there is currently no Response
class, the Request
class could potentially be retro-fitted to extend the WP_REST_Request
class. One thing to consider is the impact this may have on using the request object outside or REST controllers. As long as the class captures the request correctly, this shouldn't be a problem.
The Response
class raises a few more considerations as only REST routes return a WP_REST_Response
object currently. Initial investigation shows it's possible to return this for an AJAX call too, opening up possibilities to refactor the REST Exception handling currently in place. However, how should the response object behave outside of a routing context? Should the response have a send
method to essentially dispatch itself to the browser? Should another service take the responsibility of this? Or should the Response
object be only relevant in the routing context as is the case for the core class?
My initial preference is for the latter, as WordPress handles responses in other contexts. Is there a use case for, say, returning a 403 response in a shortcode? Probably not, and maybe this shouldn't be possible!
TLDR;
Request
class to extend WP_REST_Request
(or perhaps that should be WP_HTTP_Request
), refactor relevant methods to use the parent methods (of which there are numerous).Response
class.
Extend
WP_REST_Request
andWP_REST_Response
to improve integration with WP core