Sumit
Sumit

Reputation: 57

How to setup AWS API gateway resource to take matrix parameters?

I have been trying to setup a resource using AWS API Gateway but I can't seem to find a way to either set or access matrix parameters.

I want to be able to set up a resource similar to the following -

GET /image;height=750;width=1000;format=png

Is it possible ?

Upvotes: 0

Views: 238

Answers (3)

Akhilesh Bangalore
Akhilesh Bangalore

Reputation: 189

I realize that this is a very old question. Leaving my response in case someone has a similar challenge

There are multiple ways to set this up. It all comes down to the context in which the API is intended to be used.

While query parameters will solve the problem, they are not the best suited for representing a resource. They fit well with scenarios that involve filtering. If this API is intended to be used as a source for <img /> tags on the UI, this pattern GET .../images/{widthxheight}/{imageName}.{extension} can be used. Ex: GET .../images/200x400/sponge-bob.png

However, if the intent is for this API to be used for the purpose of looking up. the below definition can be used -

POST .../image-results
Content-Type: application/json

{
  "name":"sponge bob",
  "height": 400,
  "width": 200,
  "format": "png"
}

Upvotes: 0

Jurgen
Jurgen

Reputation: 1273

API Gateway currently does not support matrix parameters. As a workaround, you could use query parameters as already mentioned and parse them in your backend.

Best, Jurgen

Upvotes: 0

Andrew Templeton
Andrew Templeton

Reputation: 1696

You need to configure the setup to use Query Parameters.

You do this in the Method Request area of a method configuration from within the console:

https://console.aws.amazon.com/apigateway/home?region=<region-id>#/restapis/<api-id>/resources/<resource-id>/methods/<method-type>

You can also do this use the AWS API Gateway HTTP API putMethod endpoint, or the AWS#APIGateway#putMethod call in any of their SDKs.

Upvotes: 1

Related Questions