apache / apisix

The Cloud-Native API Gateway
https://apisix.apache.org/blog/
Apache License 2.0
14.49k stars 2.52k forks source link

request help: Support Backend for Frontend #4761

Open aaron-codes opened 3 years ago

aaron-codes commented 3 years ago

Issue description

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

tokers commented 3 years ago

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

juzhiyuan commented 3 years ago

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?

membphis commented 3 years ago

please change the title to English @aaron-codes

abbluiz commented 3 years ago

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?

spacewander commented 3 years ago

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

tzssangglass commented 3 years ago

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

abbluiz commented 3 years ago

@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.

spacewander commented 3 years ago

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

spacewander commented 3 years ago

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

zgLiuBing commented 3 years ago

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

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

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

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

abbluiz commented 2 years ago

@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?

spacewander commented 2 years ago

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

abbluiz commented 2 years ago

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