1

I have a wordpress site that will be replacing an old legacy site, however the old legacy site includes a SOAP API that I won't be able to re-implement in wordpress.

Is it possible for the wordpress site to accept calls to these API route, call the API itself, and then return the result to the caller as if the original API had responded? (i.e. without getting a wordpress page or some other wordpress artefact in the response?)

For example:

A call to:

www.mydomain.com/api/getcount/

would want to trigger a call to:

www.mylegacyendpoint.net/api/getcount

and return the result so that when the DNS changes and the new wordpress site goes live on the domain (replacing the old legacy site on that domain) the API calls are unaffected.

I'm not very familiar with wordpress as a platform and so I'm not sure if this is something that can be handled within wordpress or something that would need to be handed in the hosting environment

1
  • You could probably rig something up using the Rewrite API and the various HTTP functions, but if I was attacking this problem I'd start by trying to set up some 301 redirects in the WordPress site's .htaccess file to pass any requests to /api/* to the legacy server's new URL. – Pat J Jun 17 at 16:30
2

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.