Mayank
Mayank

Reputation: 958

How to remove the word ‘api’ from Azure functions url

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]

Upvotes: 23

Views: 8685

Answers (4)

Matt
Matt

Reputation: 13339

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.

Upvotes: 14

Denis Pitcher
Denis Pitcher

Reputation: 3240

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"
    }
  }
}

Upvotes: 41

Mayank
Mayank

Reputation: 958

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

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

Upvotes: 22

Jan_V
Jan_V

Reputation: 4406

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.

Upvotes: 7

Related Questions