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

gefragt vor 2 Jahren103 Aufrufe
Keine Antworten

Du bist nicht angemeldet. Anmelden um eine Antwort zu veröffentlichen.

Eine gute Antwort beantwortet die Frage klar, gibt konstruktives Feedback und fördert die berufliche Weiterentwicklung des Fragenstellers.

Richtlinien für die Beantwortung von Fragen