Using a different route prefix with Azure Functions

Sometimes you have the requirement to use a different route prefix than the one that Azure Functions auto-generates

For example: https://mynewapimc.azurewebsites.net/api/HttpTriggerCSharp1 uses api before the function name. You might want to either remove api or change it to another name.

I typically fix this by going into the Azure Portal and clicking on my Azure Function. I then click on Platform Features and Advanced tools(Kudu).

I then navigate to wwwroot and hit edit on the host.json file.

Inside the editor, add the routePrefix to define the route prefix. So if I wanted the route prefix to be blank, then I'd `use the following:

{
  "http": {
    "routePrefix": ""
  }
}
1
2
3
4
5

Simply restart your Azure Function and now my URL is accessable without api.

On the flip side, if you wanted a route prefix, then I'd just add the following

{
  "http": {
    "routePrefix": "myroute"
  }
}
1
2
3
4
5