admin管理员组

文章数量:1290426

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/api/getcount/

would want to trigger a call to:

www.mylegacyendpoint/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

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/api/getcount/

would want to trigger a call to:

www.mylegacyendpoint/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

Share Improve this question asked Jun 17, 2021 at 15:19 KaineKaine 1134 bronze badges 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 Commented Jun 17, 2021 at 16:30
Add a comment  | 

1 Answer 1

Reset to default 3

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.

本文标签: redirectCan Wordpress pass through a call to an external API and return the result directly to the client