Skip to content

Http Functions

Mathew Charles edited this page Oct 26, 2016 · 22 revisions

Routing

By default, when you create an HTTP triggered or WebHook function the function is addressable via a route of the form http://<yourapp>.azurewebsites.net/api/<funcname>. You can customize this route via the route property in your function.json file, e.g.:

{
    "bindings": [
        {
            "type": "httpTrigger",
            "name": "req",
            "direction": "in",
            "methods": [ "get" ],
            "route": "products/{category:alpha}/{id:int?}"
        },
        {
            "type": "http",
            "name": "res",
            "direction": "out"
        }
    ]
}

This function will be addressable via url http://<yourapp>.azurewebsites.net/api/products/electronics/123. This route also demonstrates support for route constraints. Documentation on the constraint formats supported can be found here.

In a C# function, you can then define parameters that bind to the route parameters like so:

public static Task<HttpResponseMessage> Run(
     HttpRequestMessage request, string category, int? id, TraceWriter log)
{
    ...
}

Here's the same function definition coded in Node.js, showing how the bound route parameter values can be accessed via context.bindingData:

module.exports = function (context, req) {
    var category = context.bindingData.category;
    var id = context.bindingData.id;

    ...
}

By default, all function routes will be prefixed with api. You can customize or remove that prefix entirely via the http.routePrefix property of function.json, e.g.:

{
    "http": {
        "routePrefix": ""
    }
}

Here we've set this to an empty string which means that no prefix will be used. So rather than http://<yourapp>.azurewebsites.net/api/<funcname> the default route for functions in the app will be http://<yourapp>.azurewebsites.net/<funcname>.

Learn

Azure Functions Basics

Advanced Concepts

Dotnet Functions

Java Functions

Node.js Functions

Python Functions

Host API's

Bindings

V2 Runtime

Contribute

Functions host

Language workers

Get Help

Other

Clone this wiki locally