HTTP routing with Azure Functions
  • Updated on 17 Apr 2019
  • 1 minute to read
  • Contributors
  • Print
  • Comments
  • Share
  • Dark
    Light

HTTP routing with Azure Functions

  • Print
  • Comments
  • Share
  • Dark
    Light

#ServerlessTips - Azure Functions
Author: Steef-Jan Wiggers Azure MVP

By default, HTTP triggered Azure Functions are addressable with a route prefix /api/. For instance, an EpochToDateTime function I created has the following URL:
https: // currencyfunctions.azurewebsites.net /api/ EPochToDateTime

The route prefixes in Azure Functions are customizable and removable using the host.json – a metadata file that contains the global configuration options affecting all functions. To modify the route prefix, you can change the host.json file to look like the following:

{
  "version": "2.0",
  "extensions": {
    "http": {
      "routePrefix": "Name"
    }
  }
}

This change will turn our URL to:
https: // currencyfunctions.azurewebsites.net /name/ EPochToDateTime

There are various ways to define function routes for individual functions:
Function header: in the method, you assign the route in the HTTP trigger binding name.

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

Define the route in the Azure Portal: you navigate to the integrate tab of your function and specify the route template.
Tip 21 - HTTP routing with Azure Functions Pic1.png

In our example, the address can be changed to:
https: // currencyfunctions.azurewebsites.net /api/ convert

To conclude you can change addresses of your functions on App level and function level – giving you the option for customizable addressing of your function endpoints. The benefit of changing your addresses is to support versioning and routing.

Was this article helpful?