DEV Community

Guido Zambarda
Guido Zambarda

Posted on • Originally published at iamguidozam.blog on

Change or remove the base /api path in Azure Functions

Cit: “Everything works and I like it, but I don’t want the /api in the URL, can you remove it?”.

That was the incipit to this post.

Before that I never wondered if there is a configuration or something to change or remove the /api base URL in Azure Functions.

After searching for a bit I found an answer and that was: yes, you can.

However the answer might change based on the host.json schema version.

For host.json file with version older than 2.0

In the host.json file there’s a property http where you can specify the base route prefix:

{ "http": { "routePrefix": "" }}
Enter fullscreen mode Exit fullscreen mode

For version 2.0 of the host.json file

In the version 2.0 of the host.json file the schema has changed and now to achieve the same result you have to incapsulate the http property inside the extensions property:

{ "version": "2.0", "extensions": { "http": { "routePrefix": "" } }}
Enter fullscreen mode Exit fullscreen mode

Hint

If you want to maintain a base URL but don’t want to keep the /api default you can change it specifying the new route prefix, for example:

{ "version": "2.0", "extensions": { "http": { "routePrefix": "ask" } }}
Enter fullscreen mode Exit fullscreen mode

In this way instead of having the /api we will have /ask.

If you want to check a sample you can view it here.

Hope that helps!

Top comments (0)