简体   繁体   中英

Azure functions single HTTP trigger with multiple methods using C#

Is this currently possible per function? By "methods" i mean multiple HTTP verbs, like "get", "post", "put", etc.

In Web API using controllers we could do that by assigning attributes that distinct method calls in a controller class.

Is there anything like this in azure functions?

Yes it is possible to specify one or more http methods for a function via the methods property in the function.json file for your function. By default methods is not specified meaning the function accepts all methods. When you specify a restricted set, only those methods are allowed, and any other methods will result in a 405 "Method Not Allowed" response.

{
    "bindings": [
        {
            "type": "httpTrigger",
            "name": "req",
            "direction": "in",
            "methods": [ "post", "put" ]
        },
        {
            "type": "http",
            "name": "$return",
            "direction": "out"
        }
    ]
}

We'll be releasing some big improvements in this area vary soon. We'll be supporting custom http routes, with full route templating etc. which will allow you to define REST APIs in the way you'd expect. Using this new functionality, you can have one function handling GET requests for a resource, and another handling PUT/POST, both using a restful route scheme like products/{category}/{id?} . These upcoming changes will allow you to accomplish all the WebAPI routing scenarios.

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