radiate-framework / framework

A WordPress plugin and theme framework
https://radiate-framework.github.io/
MIT License
4 stars 0 forks source link

Request/Response #132

Closed BenRutlandWeb closed 2 years ago

BenRutlandWeb commented 2 years ago

Extend WP_REST_Request and WP_REST_Response to improve integration with WP core

BenRutlandWeb commented 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;