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 |1 Answer
Reset to default 3I 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.
版权声明:本文标题:redirect - Can Wordpress pass through a call to an external API and return the result directly to the client? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741496790a2381870.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
.htaccess
file to pass any requests to/api/*
to the legacy server's new URL. – Pat J Commented Jun 17, 2021 at 16:30