Different response templates depending on response content

Hi,
How can I use different response body templates, depending on the response content?

I have one endpoint that returns response in following format:

{
  statusCode: 200,
  methodName: "testConnection",
  body: {
    ...
  }
}

So depending on the methodName, I’d like to pick one response template or another.

I’d probably handle this in the code:

if(methodName === "testConnection") {
  return this body
} else {
  return different body shape
}

1 Like

Interesting, what is your use case?

I am building out API endpoints as Lambda functions and I’d like to offer the response formatted in JSON and XML, depending on the request’s content-type header.