apisix icon indicating copy to clipboard operation
apisix copied to clipboard

request help: Support Backend for Frontend

Open aaron-codes opened this issue 5 years ago • 14 comments

Issue description

能否支持下图中的 API 编排能力 image

aaron-codes avatar Aug 05 '21 10:08 aaron-codes

It's not a good way to support it in Apache APISIX but you can implement it in a custom plugin.

tokers avatar Aug 05 '21 11:08 tokers

see https://apisix.apache.org/docs/apisix/plugins/batch-requests/

Now we support setting the same Query for different requests, does it make sense to you?

juzhiyuan avatar Aug 06 '21 04:08 juzhiyuan

please change the title to English @aaron-codes

membphis avatar Aug 08 '21 20:08 membphis

That's a feature I would like to see too. Other API gateways call this differently. I've seem them call it Sequential Proxy, Chained Backend Requests, and API Composition, but all of these seems to do the same basic thing. It's not the same as batch requests, because sometimes I need the response from an "upstream backend" to be included in the request of the next "upstream backend" on the pipeline, and I think batch requests only support making concurrent requests that are independent from each other.

The motivation for this feature is simply for the frontend convenience, that's why it may also be called "Backend for Frontend" (I guess that's why, not 100% sure). Specially useful for mobile clients and web apps that need to access micro-apis that separates related entities between them. Instead of making chained requests on every frontend client, why not configure them in the gateway?

abbluiz avatar Sep 02 '21 20:09 abbluiz

@abbluiz Maybe the batch-request plugin can serve this purpose?

spacewander avatar Sep 08 '21 11:09 spacewander

the batch-request plugin can sent more multiple requests, but the "Backend for Frontend" here also need to handle responses of multiple requests?

tzssangglass avatar Sep 09 '21 01:09 tzssangglass

@spacewander @tzssangglass

As I mentioned before, the batch-requests would not fully serve this purpose, because yes it would need to handle a few responses, if some request on the pipeline depends on the response of other requests.

Maybe it will become clear for you if you check the implementation of chained requests other API gateways have done, such as "Sequential Proxy" on KrakenD: https://www.krakend.io/docs/endpoints/sequential-proxy/

But perhaps I am wrong about batch-requests. Please feel free to correct me about its functionality if you still believe it would achieve the same goal I am trying to describe.

abbluiz avatar Sep 10 '21 12:09 abbluiz

I see. To support it, currently we have to write a custom plugin.

spacewander avatar Sep 10 '21 13:09 spacewander

@18300618319 suggested that we can study the API orchestration from the other gateways in https://github.com/apache/apisix/issues/5076

spacewander avatar Sep 17 '21 01:09 spacewander

fizz-gateway这个API编排挺好用的

------------------ 原始邮件 ------------------ 发件人: @.>; 发送时间: 2021年9月17日(星期五) 上午9:44 收件人: @.>; 抄送: @.>; @.>; 主题: Re: [apache/apisix] request help: Support Backend for Frontend (#4761)

@18300618319建议我们可以研究来自其他网关的 API 编排#5076

— 你收到这个是因为你被提到了。 直接回复此邮件,在 GitHub 上查看或取消订阅. GitHub Mobile 上的分流通知监督办或机器人.

zgLiuBing avatar Sep 17 '21 01:09 zgLiuBing

@spacewander How would I write a custom plugin for this? Would you recommend using the ext-plugin-post-req with Python, for example? Could I make additional request inside this external plugin?

abbluiz avatar Jan 11 '22 17:01 abbluiz

Yes, you can make additional request inside the external plugin. There is a real-world example (not in Python): https://github.com/swisscom/apisix-opa-plugin/blob/master/auth.go

Or you can do it in the Lua, like https://github.com/apache/apisix/blob/master/apisix/plugins/forward-auth.lua

spacewander avatar Jan 12 '22 02:01 spacewander

@spacewander Interesting. I will be trying that out in the future.

abbluiz avatar Jan 12 '22 17:01 abbluiz

If there is still a problem, please open it again.

Baoyuantop avatar May 19 '25 03:05 Baoyuantop