HTTP API Gateway - HTTP URI Integration fails when query contains spaces

1

I have an HTTP API Gateway with a "search" route that calls an external API via the HTTP URI integration type. I want to map the query string parameter "song" in my API to "q" in the external API, with a static prefix added. For example, GET /search?song=Yesterday should map to https://external-api/search?q=The+Beatles+-+Yesterday.

This works in my example above, but breaks if the original query contains a space (e.g., searching for Hey Jude instead of Yesterday).

The only workaround I have found is to URL encode the original query twice (e.g. calling my API with GET /search?song=Hey%2520Jude).

My current parameter mapping is as follows:

Parameter to modifyModification typeValue
querystring.qOverwritethe%20beatles%20-%20$request.querystring.song

I've tried the following to no avail:

  • + instead of %20
  • Removing the prefix and just mapping q to $request.querystring.song
  • Adding brackets (e.g., ${request.querystring.song})

I would like to be able to map GET /search?song=Hey%20Jude to https://external-api/search?q=The%20Beatles%20-%20Hey%20Jude without having to double-encode my input (as this would be annoying for people calling my API).

已提問 2 年前檢視次數 103 次
沒有答案

您尚未登入。 登入 去張貼答案。

一個好的回答可以清楚地回答問題並提供建設性的意見回饋,同時有助於提問者的專業成長。

回答問題指南