apisix icon indicating copy to clipboard operation
apisix copied to clipboard

How to get the response of the upstream and send it to an external service for transformation

Open vaibhavsw opened this issue 3 years ago • 6 comments

Description

How do I capture the response body, headers, and status codes from the response of Upstream, send it to an external service for transformation and processing, and then send the response back from the transformation service to the client?

In this direct response of the upstream is not sent to the client, rather the response from the upstream is modified by an external service, and then the response of modification is then sent to the client

Environment

  • APISIX version (run apisix version): 2.15
  • Operating system (run uname -a): MacOS
  • OpenResty / Nginx version (run openresty -V or nginx -V): nginx version: openresty/1.21.4.1
  • etcd version, if relevant (run curl http://127.0.0.1:9090/v1/server_info): 3.4.15
  • APISIX Dashboard version, if relevant:
  • Plugin runner version, for issues related to plugin runners:
  • LuaRocks version, for installation issues (run luarocks --version): 3.8.0

vaibhavsw avatar Sep 14 '22 08:09 vaibhavsw

Using the ext-plugin (go-runner/java-runner/python-runner) is a good choice, but the response body is not yet supported. The good news is that we are currently preparing support.

However, the converted response is still sent to the client by APISIX.

soulbird avatar Sep 14 '22 08:09 soulbird

@soulbird I didn't get what I do right now to get it working. Any workaround you think can give this flow?

vaibhavsw avatar Sep 14 '22 08:09 vaibhavsw

and then send the response back from the transformation service to the client?

Unable to do this. This requires client APISIX, and external services to cooperate with each other.

There is something strange about this working model, are there any publicly available examples?

tzssangglass avatar Sep 14 '22 09:09 tzssangglass

@tzssangglass There are no examples as this a custom requirement where we do not want to expose the JSON sent from the client, rather modify them depending on some rules and then send that as a response.

vaibhavsw avatar Sep 14 '22 09:09 vaibhavsw

There are no examples as this a custom requirement where we do not want to expose the JSON sent from the client, rather modify them depending on some rules and then send that as a response.

And why let transformation service return response to the client directly? When this request is proxied from the client to the upstream by APISIX, the response will also be proxied form upstream to client by APISIX.

tzssangglass avatar Sep 14 '22 14:09 tzssangglass

The response received from upstream needs to be transformed that is why it needs to be intercepted within APISIX itself

vaibhavsw avatar Sep 14 '22 15:09 vaibhavsw

This issue has been marked as stale due to 350 days of inactivity. It will be closed in 2 weeks if no further activity occurs. If this issue is still relevant, please simply write any comment. Even if closed, you can still revive the issue at any time or discuss it on the [email protected] list. Thank you for your contributions.

github-actions[bot] avatar Sep 09 '23 10:09 github-actions[bot]

This issue has been closed due to lack of activity. If you think that is incorrect, or the issue requires additional review, you can revive the issue at any time.

github-actions[bot] avatar Sep 24 '23 10:09 github-actions[bot]