Skip to content

help request: I want to rewrite the information returned by the interface in serverless-post-function #12104

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
flyletc opened this issue Mar 31, 2025 · 6 comments
Labels
question label for questions asked by users

Comments

@flyletc
Copy link

flyletc commented Mar 31, 2025

Description

hello
I want to rewrite the information returned by the interface in serverless post function. How can I obtain the information returned by the interface and complete the rewriting logic to return it to the frontend. Please tell me how to do it

Environment

  • APISIX version 3.11.0
  • Operating system rocky linux x86_64
@dosubot dosubot bot added the question label for questions asked by users label Mar 31, 2025
@Baoyuantop
Copy link
Contributor

Maybe you can try this plugin https://apisix.apache.org/docs/apisix/plugins/response-rewrite/

@flyletc
Copy link
Author

flyletc commented Apr 1, 2025

Maybe you can try this plugin https://apisix.apache.org/docs/apisix/plugins/response-rewrite/

Thank you very much. I have reviewed the corresponding documents, but there are still some difficulties for me as I do not have a complete example

I expect to obtain the content returned by the interface, then determine whether the interface content meets a certain condition, and then call another service's interface query. Based on the queried content, I rewrite the interface return and return the rewritten content to the frontend

I am unable to retrieve the content returned by the interface

@kayx23
Copy link
Member

kayx23 commented Apr 1, 2025

Some clue with working with response body: https://docs.api7.ai/hub/serverless-functions#modify-a-specific-field-in-response-body

@Baoyuantop
Copy link
Contributor

Does this plugin fit your design? https://github.com/bzp2010/apisix-plugin-pipeline-request

@flyletc
Copy link
Author

flyletc commented Apr 2, 2025

Some clue with working with response body: https://docs.api7.ai/hub/serverless-functions#modify-a-specific-field-in-response-body

Thank you very much, but I have encountered a new problem,serverless-post-function phase body_filter

local http = require "resty.http"
local httpc = http.new()

error message

2025/04/02 06:58:32 [error] 54#54: *10167174 failed to run body_filter_by_lua*: /usr/local/apisix/apisix/patch.lua:372: API disabled in the context of body_filter_by_lua*
stack traceback:
        [C]: in function 'error'
        /usr/local/openresty/lualib/resty/core/socket/tcp.lua:292: in function 'original_tcp'
        /usr/local/apisix/apisix/patch.lua:372: in function 'ngx_socket_tcp'
        /usr/local/apisix//deps/share/lua/5.1/resty/http.lua:133: in function 'new'
        [string "return function (conf,ctx)..."]:44: in function 'func'
        /usr/local/apisix/apisix/plugins/serverless/init.lua:84: in function 'phase_func'
        /usr/local/apisix/apisix/plugin.lua:1206: in function 'run_plugin'
        /usr/local/apisix/apisix/plugin.lua:1239: in function 'run_global_rules'
        /usr/local/apisix/apisix/init.lua:451: in function 'common_phase'
        /usr/local/apisix/apisix/init.lua:806: in function 'http_body_filter_phase'

@flyletc
Copy link
Author

flyletc commented Apr 2, 2025

Does this plugin fit your design? https://github.com/bzp2010/apisix-plugin-pipeline-request

Thank you very much, I will try it out

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question label for questions asked by users
Projects
Status: 📋 Backlog
Development

No branches or pull requests

3 participants