In this Azure tutorial, we will discuss Azure Function HTTP trigger.
Azure Function is an Azure Service from Microsoft that helps you to run some pieces of code smoothly without getting worried about the infrastructure for your application. Check out some more information on Azure Function before starting with the Azure Function HTTP Trigger.
- How Much Memory Available For Azure Functions
- Where To Instantiate Database Connection In Azure Functions
The main work of the Azure Function HTTP trigger is to invoke the Azure Function with the HTTP Request. HTTP Trigger is the basic and simplest trigger of an Azure Function. Mostly, People use the HTTP Trigger while performing the operation with the Azure Function.
Basically, there are two response codes that HTTP Triggered functions to return
- It returns the response code as HTTP 204 if there is no content.
- It returns the response code as HTTP 200 OK in case everything is ok and the Successful execution of the Azure Function.
The HttpTrigger attribute is available in the case of C# language, Java, etc, to configure your Azure Function.
To execute the HTTP-triggered Azure function, you need to specify the authorization types. If you are running the Azure Function locally, in that case, the authorization attribute will be ignored. Once you publish your Azure Function into the Azure cloud then the authorization will work. There are a few authorization types available below
- Function: This is the default authorization type option available. This is the key-based authorization type. A function-specific API key is required for this authorization type.
- Anonymous: There is no restriction, anyone can access and No API key is needed for the Anonymous Authorization type.
- Admin: For the Admin authorization type, the master key is required to access the Azure function.
You can provide the HTTP-triggered Azure function parameter value along with the query string in the function URL or in the Body in a JSON format.
When you create an HTTP-triggered Azure function, by default, the URL of the function is in the below format
http://<APP_NAME>.azurewebsites.net/api/<FUNCTION_NAME>One of the Examples for an HTTP triggered Azure function URL with the authorization type as Function is as below
https://mydemoazurefunction1220200810210756.azurewebsites.net/api/Function1?code=CNZkNlmz3xpQRhgu7DIKcRiMiTtLv7bTOvhcip82GdfCkormbvCqjw==Below is the example of an HTTP-triggered Azure function function.json file
{
"bindings": [
{
"authLevel": "function",
"name": "req",
"type": "httpTrigger",
"direction": "in",
"methods": [
"get",
"post"
]
},
{
"name": "$return",
"type": "http",
"direction": "out"
}
]
}If we discuss a little bit on the above function.json file,
type: The type property is required to mention, and the value will be httpTrigger.
direction: The property direction is also required, and the value must be set to in.
name: The property name is required and needs to mention the variable name in the code for the Azure function. authLevel: The property authLevel needs to specify the authorization level for the Azure function. You can provide the auth level property value as Function, Anonymous, or Admin. The default option is Function.
methods: You can specify the HTTP methods to which the Azure Function responds. If you do not mention any specific method, then your Azure function will respond to all the HTTP methods available. This is about the Azure function HTTP trigger authentication.
Let’s create an Azure Function HTTP Trigger using Visual Studio 2019
Create An HTTP Trigger Azure Function Using Visual Studio 2019
Well, let’s create an HTTP-triggered Azure Function using Visual Studio 2019. Follow the below steps to create the Azure function.
1. The first step is to open Visual Studio 2019.

2. Once the Visual Studio is loaded successfully, Now you need to click on the Create a new Project button from the Get Started window.

3. On the Create a new project window, Now search for the Azure Functions template, choose the Azure Functions and then click on the Next button to go to the next screen.

4. Enter your Project name, and choose a location where you want to save the Azure function project. On the Configure Your New Project window, click on the Create button.

5. We need to choose the trigger for our Azure Function, so choose the Http trigger as the trigger option. For the Storage Account (AzureWebJobsStorage) option, select the Storage Emulator option and Choose the Authorization level option as Anonymous On the Create a new Azure Functions Application window. Now click the Create button to create the HTTP-triggered Azure function, as shown below.
