user246392
user246392

Reputation: 3017

How to use strongly typed http methods in an Azure function signature

I have a bunch of Azure functions that use an http trigger. I've been hard-coding http methods like in the below case:

[FunctionName("HttpTriggerCSharp")]
public static async Task<IActionResult> Run(
    [HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)]
    HttpRequest req, ILogger log)

Ideally, I'd like to use a strongly typed value instead of hard-coded strings like get and post. I tried using HttpMethod enum values, but I'm getting the below error:

An attribute argument must be a constant expression , typeof expression or array creation expression of an attribute parameter type

Using C#, is there a way to leverage strongly typed http methods when declaring the function method signature?

Upvotes: 1

Views: 485

Answers (1)

Machiel Visser
Machiel Visser

Reputation: 925

nameof(HttpMethod.Get) should work.

Upvotes: 4

Related Questions