這個專案專注於利用 YARP 來實作 API Gateway。
The project focuses on implementing an API Gateway using YARP.
練習 YARP 實作 API Gateway。
To practice how YARP implement API Gateway.
- 轉換(Transforms)
- 負載平衡(Load Balancing)
- 健康檢查(Health Checks)
- 要求逾時(Request Timeouts)
- 認證授權(Authentication and Authorization)
- 外部與 API Gateway 的 JWT 驗證
- API Gateway 與其它 API 的 HMAC 驗證(補強僅在 API Gateway 驗證的漏洞)
- 分散追蹤(Distributed tracing)
- CORS(Cross-Origin Requests)
- 利用 .NET 組態檔機制區分容器應使用哪些內容
- 調整可以透過環境變數覆蓋組態(容器應用上較彈性)
- Container 環境限制應與 Production 環境一致
開啟終端機至專案根目錄並執行以下指令
-
Open the terminal to the project's root directory and execute the following command.
(docker or podman) compose -p yarp-demo up -d
透過
GatewayApi呼叫ProductsApi
-
Call
ProductsApithroughGatewayApi.curl -X GET --location "http://localhost:5000/products-api/products/1" -H "Accept: application/json"
回應如下:
The response is as follows:
{ "id": "1", "name": "Apple" }
透過
GatewayApi呼叫SalesApi
-
Call
SalesApithroughGatewayApi.curl -X GET --location "http://localhost:5000/sales-api/sales/1" -H "Accept: application/json"
回應如下:
The response is as follows:
{ "id": "1", "name": "Ame" }
透過
GatewayApi呼叫UsersApi
-
Call
UsersApithroughGatewayApi.curl -X GET --location "http://localhost:5000/sales-api/sales/1" -H "Accept: application/json"
回應如下:
The response is as follows:
{ "id": "1", "name": "Ben" }
嘗試自己玩看看
- Try it yourself.