Description
As touched on in Azure/azure-functions-nodejs-worker#664 a scenario for a pre/post invocation hook, when used like middleware, would be to cancel/abort the execution of the Function, and even provide an alternative out
binding.
Here's a scenario:
You have a REST API using Azure Functions to handle the user interactions. To ensure that you don't rely on the client to provide valid data you want to perform server validation based off a validation schema. As this is a REST API you can infer the object you're validating from the URL of the request, so rather than having each function perform its own validation you want a piece of middleware to do it.
If the validation passes, then you want to call to "original" Function so that data is persisted/etc. but if it fails validation you want to respond with a400 Bad Request
and provide the error messages.
Currently there is no way to say "stop execution" or "execute this Function instead" from within a hook, without overriding functionCallback
property of the HookContext
, but that's probably not recommended.
From a billing/usage standpoint, we should still treat the Function as "executed", even if there is an early abort provided, as you've still executed something in context of that Function invocation.
Activity