Kasbolat Kumakhov
Kasbolat Kumakhov

Reputation: 721

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?

Upvotes: 4

Views: 5934

Answers (1)

mathewc
mathewc

Reputation: 13558

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.

Upvotes: 6

Related Questions