Click here to Skip to main content
15,886,137 members
Articles / Hosted Services / Azure

How to remove /api from Azure Functions URLs

Rate me:
Please Sign up or sign in to vote.
4.00/5 (1 vote)
15 Aug 2019CPOL1 min read 1.7K   2  
How to customize the URLs of your Azure Functions

Note: All of the following assumes you’re working with Azure Function 2.0.

Azure Functions are great. By default, all HTTP functions on Azure have their URLs prefixed with /api. For example, if you have functions named Function1 and Function 2, you’d reach them by calling http://my-app.azurewebsites.net/api/Function1 and http://my-app.azurewebsites.net/api/Function2.

Usually, this is fine. But it seems like an arbitrary restriction. What if you’d rather not have it?

Fortunately, there’s a configuration option in your function app’s host.json file to change it. Unfortunately, as I’m writing this, Microsoft’s documentation is incorrect.

It tells you your host.json should look something like this if you want to remove the /api prefix:

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

This won’t work. If you’re running Visual Studio, it’ll tell you Property name is not allowed by the schema. Instead, the http object must be placed inside of extensions:

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

Setting routePrefix to an empty string removes /api from the URL. Now, to access Function1, you’d call http://my-app.azurewebsites.net/Function1.

Also note the version property. If you don’t add this, the Azure Functions local simulator will flip out and fall into an infinite loop of scary-looking error messages:

Image 1

If host.json is blank, the simulator will be fine. But as soon as you add anything else to host.json, you also have to add a version, or the simulator will go crazy.

And that’s it! You now know how to remove /api from your Azure Functions URLs. You can also use a non-blank string to use a prefix other than api. If you’d like your functions URLs prefixed by popcorn or cats, there’s nothing stopping you!

The post How to remove /api from Azure Functions URLs appeared first on Ryan Peden.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer My House
Canada Canada
I spent 5 years working for Ottawa startups before returning home to Toronto. During Covid I decided to escape the big city and moved north to Penetanguishene, Ontario.

I'm a .NET/JavaScript/TypeScript developer and technical writer by day, but in the evening you'll often find me cooking up projects in Ruby, Haskell, Clojure, Elixir, and F#.

Comments and Discussions

 
-- There are no messages in this forum --