Hello, I’m trying to build out a REST API using lambda functions, with the goal of cleanly separating functionality at function level, and hopefully avoiding excessive routing inside the function handler. For example, a simple REST API might look like
GET /widgets/:id -> getWidgetId // get a widget by id POST /widgets/ -> postWidget // create new widget PUT /widgets/:id -> putWidgetId // update a widget with given id DELETE /widgets/:id -> deleteWidgetId // delete widget by id
(using function name conventions generated by openapi generator, but they could be anything)
I know how to do this with nginx, and with AWS API gateway it seems that you’d use Methods on Resources. However, I can’t seem to find anything in the netlify redirects documentation on how to match the request based on the method, like you would based on country, role, etc.
The only solutions I can see are (1) stand up a proxy nginx server elsewhere and have that rewrite e.g. a DELETE to a POST to the respective netlify endpoint with a method query parameter (preserves function separation but requires an external service) and (2) send all method requests to the same function then dispatch internally based on APIGatewayEvent’s httpMethod (doesn’t require external routing but conflates unrelated logic in each function, not very RESTy).
Ideally I’d want something like
/widgets/:id Method=DELETE /.netlify/functions/deleteWidgetId 200
Is this not possible currently? Is there a better approach for routing these?