简体   繁体   中英

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?

nameof(HttpMethod.Get)应该可以工作。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM