Is it possible to define a `ApiGatewayV1ApiRoutePr...
# help
k
Is it possible to define a
ApiGatewayV1ApiRouteProps
instance without a Function, but just an API Gateway Mock Integration? Or will I get errors from SST?
Reading the source, the answer is that I can't have a mock integeration.
f
Hey @kierans777, that’s not yet supported by the
ApiGatewayV1Api
, but you can do it in CDK with something like this:
Copy code
const api = new sst.ApiGatewayV1Api(...);

api.restApi.root.addResource('pets').addMethod('GET', new MockIntegration({
  integrationResponses: [{
    statusCode: '200',
  }],
  passthroughBehavior: PassthroughBehavior.NEVER,
  requestTemplates: {
    'application/json': '{ "statusCode": 200 }',
  },
}), {
  methodResponses: [{ statusCode: '200' }],
});
Essentially,
api.restApi
gives you the CDK RestApi construct, and you can use integrations that are not yet supported by SST.
Let me know if that makes sense.
k
Thanks @Frank, that does make sense. Is there a plan to make the
Api
constructs more rich? For example 1. IMO if you don't have a verb for a route the API should return an HTTP 405 "Method Not Allowed" which can be achieved with a Mock Integration 2. If I want my endpoint to use a Custom Authoriser and then put the request payload onto a SQS queue, then I have to use the integration approach above where it would be great to make use of the routing DSL SST has ie:
Copy code
new ApiGatewayV1Api(this, "Api", {
  routes: {
    "GET    /notes": "src/list.main",
    "POST   /notes": new AwsIntegration(...),
  },
});
I'm happy to open GitHub issues if there's a place for such ideas. (One thing that annoyed me about the Serverless platform is it's focus on Lambda's to the detriment of everything else, and good API design)
f
Hey @kierans777, yeah we definitely want to make the construct more feature rich. We have mostly been receiving requests for the
Api
construct (ie.
Api
support ALB and HTTP proxy integrations). And we more open issues for adding SQS and StepFunctions integrations.
We are getting lesser requests for the
ApiGatewayV1Api
construct, and hence it’s a bit thin on features.
It’d be great if you can open an issue for the integrations you are looking for (ie. Mock and SQS), we will make sure to prioritize them!
k
Thanks @Frank. Until such time as AWS brings features like Usage Plans, API Keys, Mock Integrations, etc to HTTP Apis I think it's important not to neglect people who need to use those features, and who want to use SST.
f
Yeah for sure 🙌 While one can still configure Usage Plans, API Keys, etc the CDK way inside SST, we do want to bake into the SST construct and make it easier to configure them.