[GitHub] [apisix] chilcano commented on issue #9928: help request: Dynamic routing based on HTTP_STATUS from first API
chilcano commented on issue #9928: URL: https://github.com/apache/apisix/issues/9928#issuecomment-1663533178 Hi @sanjivkamate - I think you should create a separate Github issue, once done, I'm happy to help you. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: notifications-unsubscr...@apisix.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org
[GitHub] [apisix] chilcano commented on issue #9928: help request: Dynamic routing based on HTTP_STATUS from first API
chilcano commented on issue #9928: URL: https://github.com/apache/apisix/issues/9928#issuecomment-1662182931 Thanks @shreemaan-abhishek for sharing this information. Definitely, I'm missing out something in my code. __Questions:__ __1. What libraries are available in each phase?.__ I changed the plugin phase from `_M.access()` to `_M.header_filter()` and now I'm having this error when the plugin is being executed. ```sh .. 2023/08/02 11:21:15 [error] 51#51: *4647263 failed to run header_filter_by_lua*: /usr/local/apisix/apisix/patch.lua:372: API disabled in the context of header_filter_by_lua* stack traceback: [C]: in function 'error' /usr/local/openresty/lualib/resty/core/socket/tcp.lua:271: 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' /opt/apisix/plugins/api2-plugin.lua:41: in function 'make_request_to_url' /opt/apisix/plugins/api2-plugin.lua:123: in function 'phase_func' /usr/local/apisix/apisix/plugin.lua:1134: in function 'common_phase' /usr/local/apisix/apisix/init.lua:760: in function 'http_header_filter_phase' header_filter_by_lua:2: in main chunk, client: 172.19.0.1, server: _, request: "GET /mychainedapi/hello HTTP/1.1", host: "127.0.0.1:9080" ... ``` This means there are not libraries available in that phase. If so, what libraries can be used there? __2. If only some libraries are accessible in each phase, how I can chain the execution of 2 plugins where the response of the 1st plugin is available in the 2nd plugin__ Each plugin (api1-plugin and api2-plugin) call external Endpoint URL Any idea is welcome. Regards. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: notifications-unsubscr...@apisix.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org
[GitHub] [apisix] chilcano commented on issue #9928: help request: Dynamic routing based on HTTP_STATUS from first API
chilcano commented on issue #9928: URL: https://github.com/apache/apisix/issues/9928#issuecomment-1660741344 Thanks @qwzhou89 I've found a way to share info from a 1st plugin to 2nd plugin. I enabled `nginx.http.custom_lua_shared_dict` in the apisix configuration (`config.yaml`). I used this config: ```yaml apisix: ... nginx_config: http: custom_lua_shared_dict: my_shared_dict: 10m# Specify the size in MB of the shared memory zone (change as needed) deployment: ... plugins: ... ``` The example here [Chaining API requests with API Gateway Demo](https://github.com/Boburmirzo/apisix-plugin-pipeline-request-demo) works only if the 1st call is a GET with not query-string and the 2nd call manipulate the response. What if the 1st call is POST and a json request is sent? That is why I'm trying to implement in 2 plugins but in the same route. However, now I'm stuck and I can not be able to execute the `api1_plugin` firstly and `api2_plugin` later. I've followed the recommendations [Plugins execution order](https://docs.api7.ai/apisix/key-concepts/plugins#plugins-execution-order), changed the priority, the phase and always the plugin that implements `function _M.access(conf, ctx)` is executed. Am I missing something? How I can execute sequentially different plugins configured in the same route? Any recommendation here is appreciated. Regards. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: notifications-unsubscr...@apisix.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org
[GitHub] [apisix] chilcano commented on issue #9928: help request: Dynamic routing based on HTTP_STATUS from first API
chilcano commented on issue #9928: URL: https://github.com/apache/apisix/issues/9928#issuecomment-1660117949 > Why do you want access the response body and headers? thinking If you have very complex requirements you might have to write your own plugin. Thanks @shreemaan-abhishek for your support. I've tried to extend existing example available here [Chaining API requests with API Gateway Demo.](https://github.com/Boburmirzo/apisix-plugin-pipeline-request-demo). I've created 2 plugins (`api1-plugin` and `api2-plugin` ) and use both in the same route. The `api1-plugin` call to 3rd party `api1` and the `api1` json response is used to make a call to 3rd party `api2` through `api2-plugin`. In simple words, I'm trying to chain 2 APIs, however the challenge I'm facing is how to retrieve the response of 1st plugin from 2nd plugin. I've tried `ngx.var.*` and `ngx.ctx.*` to share info from 1st to 2nd plugin and that didn't work. I'm using 2 plugins because each plugin is calling different upstreams with different requests. Any idea on how get this? Appreciate your support. Regards. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: notifications-unsubscr...@apisix.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org
[GitHub] [apisix] chilcano commented on issue #9928: help request: Dynamic routing based on HTTP_STATUS from first API
chilcano commented on issue #9928: URL: https://github.com/apache/apisix/issues/9928#issuecomment-1659908965 Thanks @qwzhou89 Quick questions: 1. What is `$status` in the first route? 2. In the 2nd route. Why not using the `/api1` response (HTTP_STATUS or json body) instead of using custom header `X-Api1-Status`?. I've tried this approach, but I don't know how get the `/api1` response (headers, json body) in the 1st `proxy-rewrite` plugin from 2nd plugin `serverless-post-function`. This is my only 1 route. ```json { "uri": "/api1/*", "methods":["GET"], "plugins": { "proxy-rewrite": { "host": "random-data-api.com", "uri": "/api/v2/banks", "scheme": "https" }, "serverless-post-function": { "phase": "body_filter", "functions": [ "return function(conf, ctx) -- Print the iban value of json_response end" ] } }, "upstream_id": 1 }' ``` The Random Banks API (https://random-data-api.com/api/v2/banks) returns this: ```json { "id": 5243, "uid": "f38123fc-7c1d-4705-980f-3e82e770b100", "account_number": "0638101451", "iban": "GB86RWJD49924585669735", "bank_name": "UBS CLEARING AND EXECUTION SERVICES LIMITED", "routing_number": "290583418", "swift_bic": "BOFAGB3SSWI" } ``` And the upstream is: ```json { "name": "Random API upstream", "type": "roundrobin", "scheme": "https", "nodes": { "random-data-api.com": 1 } } ``` Should I use `serverless-pre-function` and different `phase` ? Or should I use a custom plugin? Appreciate your support. Regards. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: notifications-unsubscr...@apisix.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org