22

When you create an Http triggered API, Azure function hosts it on

https://[function-app-name].azurewebsites.net/api/[Route-configured-in-application]

Is there any way of getting rid of the term api from the URL and make it look like:

https://[function-app-name].azurewebsites.net/[Route-configured-in-application]
Mayank
  • 908
  • 9
  • 14

4 Answers4

36

The Azure Functions v2 solution is covered in this answer, the http bit needs to be wrapped in an extensions property.

{
  "version": "2.0",
  "extensions": {
    "http": {
      "routePrefix": "customPrefix"
    }
  }
}
Denis Pitcher
  • 3,080
  • 1
  • 27
  • 19
  • Great, it's working for me. thank you very much! @Mayank please mark this as the answer, your answer is not working :( – Le Khiem Sep 09 '19 at 05:45
21

Edit the host.json file and set routePrefix to empty string:

{
  "http": {
    "routePrefix": ""
  }
}
Nate
  • 698
  • 1
  • 7
  • 18
Mayank
  • 908
  • 9
  • 14
13

The accepted answer no longer works if you're using version 2 functions, instead you need to put the http settings in an extensions property:

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

You can get caught out looking at the hosts.json reference because if you only look at the http section it shows just the http properties so make sure to check the start of the doc for the top level hosts.json format.

Matt
  • 12,569
  • 4
  • 44
  • 42
7

You could also leverage the power of Azure Function Proxies for this, which might be better if you want to be explicit about which methods or routes you want to access.

Just create a proxy.json file and add the following piece of JSON to it.

{
  "$schema": "http://json.schemastore.org/proxies",
  "proxies": {
    "myazurefunctionproxy": {
      "matchCondition": {
        "methods": ["GET"],
        "route": "/{slug}"
      },
      "backendUri": "https://%WEBSITE_HOSTNAME%/api/{slug}"
    },
  }
}

This sample will redirect all GET-requests to a route with /api/ prefixed.

Jan_V
  • 4,244
  • 1
  • 40
  • 64