Function rewrites based on HTTP method for REST API

Hi @fool, thanks for the reply.

The high level reason to separate the different verb handlers into their own functions is that they represent separate logic flows – my GET and DELETE handlers don’t share any code aside from env var loading, for example (and even if they did, I would probably abstract it into an import). So having multiple flows in a single function ends up being a kind of mini “lambda-monolith”, which may or may not be an antipattern, depending on who you ask. I am also concerned that if only one “sub-route” has a heavy dependency, it will need to be loaded even when accessing a more lightweight aspect of the same resource.

Besides, in my view, you definitely do end up doing “routing” – switch (event.httpMethod) to dispatch to the correct flow. Not a huge deal, but I’d prefer to keep it out of the code, especially given that other kinds of routing (/widgets/:id vs /widgets/:id/subwidget) do in fact happen in rewrites.

So, to sum it up, I’d like to have the absolute minimum amount of code per function, to keep my source clean, concerns separated, and bundle size that needs to be loaded at every function execution minimized. I’m a little bit surprised that no one has suggested this as an enhancement to Expanding functionality of redirects, given that e.g. aws API gateway supports it (as do most web frameworks). But maybe this is because I am going about things wrong!

All that being said, edge handlers sounds just like what I’m looking for! Will sign up for the beta.

1 Like