I have an Azure Functions app.
I was surprised to learn that when defining a Azure WebJob function the HttpTriggerAttribute does not have to be applied to a HttpRequest parameter.
So while this is valid, and matches most tutorials and examples,
[FunctionName("get")]
public async Task<IActionResult> Get(
[HttpTrigger(AuthorizationLevel.Anonymous, nameof(HttpMethods.Get), Route = "api/get")]HttpRequest httpRequest)
This is also valid,
[FunctionName("post")]
public async Task<IActionResult> Post(
[HttpTrigger(AuthorizationLevel.Anonymous, nameof(HttpMethods.Post), Route = "api/post")]MyType body)
Since the attribute is not tied to a HttpRequest parameter, I'm surprised the attribute is a parameter attribute and not a method attribute like,
[FunctionName("post")]
[HttpTrigger(AuthorizationLevel.Anonymous, nameof(HttpMethods.Post), Route = "api/post")]
public async Task<IActionResult> Post(MyType body)
Why is the HttpTriggerAttribute implemented as a parameter attribute and not a method attribute like FunctionNameAttribute?
For C # class library development, FunctionName acts as a marker, marking methods as function entry points. It does not involve the input of a function. However, the trigger property is different. It not only has the function of marking the Function type, but also the role of binding input data to method parameters. These data are needed when processing the method. You can think of the trigger property as a binding of the type 'direction in'. This type of binding needs to be entered as a parameter in the development method of the C # class library. Bindings of type 'direction out' are defined outside the function as outputs. Its characteristics are so.
Example of a standard C # class library Function: https://learn.microsoft.com/en-us/azure/azure-functions/functions-bindings-example#class-library-example