Can WordPress pass through a call to an external API and return the result directly to the client?

I think most of the possibilities using something like a rewrite rule to execute a some PHP to forward and return the request at an action very early in the WordPress request’s lifecycle would have a number of drawbacks.

Other alternatives would be in using a rewrite rule to direct the request to a custom PHP AJAX handler or REST API endpoint or controller and forward on the request from there – both of these mechanisms are designed to load a smaller portion of WordPress’s core. But in all of the above options, the overhead of loading WordPress, parsing the original request, and building a new one for each proxied request is still significant in my opinion. They also introduces an additional point of failure. But they’re all certainly possible, and you can definitely return responses without the extra headers which WordPress typically adds.

It would be far easier and more efficient to perform this forwarding operation at the webserver level (or reverse proxy/load balancer prior to the webserver, if your architecture uses such a mechanism), using Apache’s ProxyPass directive as facilitated by mod_proxy, or Nginx’s equivalent directives.

error code: 523