使用 Amazon API Gateway 和 HTTP 代理整合建立 REST API 應用程式

建立 API

API Gateway 建立一個 REST API。

  • API name: HTTPProxyAPI

建立 resource 如下:

  • Resource path: /
  • Resource name: {proxy+}

建立 method 如下:

部署

點選 Deploy API 按鈕,並建立 stage 如下:

  • Stage name: test

測試

點選 Test 頁籤,進行測試:

  • Method type: GET
  • Path: petstore/pets
  • Query strings: type=fish

點選 Test 按鈕。

或使用 curl 測試。

1
curl -X GET 'https://xxx.execute-api.ap-northeast-1.amazonaws.com/test/petstore/pets'

回應如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
[
{
"id": 1,
"type": "fish",
"price": 249.99
},
{
"id": 2,
"type": "fish",
"price": 124.99
},
{
"id": 3,
"type": "fish",
"price": 0.99
}
]

參考資料