Open In App

Microsoft Azure – Custom Handlers for Azure Functions

Improve
Improve
Like Article
Like
Save
Share
Report

In this article, we will learn how to create custom handlers for Azure Functions. Custom handlers are lightweight web servers that receive events from the Azure Functions host and can be implemented with any language that supports HTTP calls. Let’s create a custom handler function app. To create a custom handler, you need to install the latest version of Go and the Azure Functions Core Tools, Visual Studio Code, and the Azure Functions extension for Visual Studio Code. 

Implementation:

Follow the below steps o create custom handlers for Azure functions:

Step 1: Let’s first create a local function. Pick a folder, and for the language, we’ll pick a custom handler, which can be implemented in any language that supports HTTP calls. 

 

Step 2: Next, we use the HTTP trigger, and we’ll call it “Go Example.” 

 

Step 3: We’ll leave this anonymous.

 

Step 4: Let’s add it to the workspace. And, this is the local function. 

 

Step 5: Now, we’ll add a new file and we’ll call it “Handler.go.” And, we’ll put the code in it. This is the custom handler. Here, it forwards the HTTP trigger calls to the custom Go handler called “Hello Handler.” It is important that this name there is the same as the name of the function. The custom handler calls the Go code that we want to execute.

 

Step 6: Open a terminal window. Now, we’ll compile the Go files with this. This produces Handler.exe, which we’ll use.

 

Step 7: Now, we need to change the host to a JSON file. Here, we need to change the custom handlers section. This points to the handler.exe file. If you do this on Linux, the file is called different as it doesn’t have EXE at the end. 

 

Step 8: Let’s open the terminal again. Now, we’ll run the function. It is running at the URL.

 

Step 9: Let’s try that in a browser, and we’ll add the name parameter to it, which the code will display. This result comes from code that is executed from the Go code file. 

 

Step 10: Now, let’s publish this to Azure. We’ll start the Wizard, and pick the “Advanced Option.” First, let’s give the function app a name. Now, pick “Custom Handler” again, and we’ll use Windows as the OS. Then, pick a resource group, and now pick a storage account. It’s creating the function app in Azure and deploying the code to it. And, in the new function app in Azure. Right-click and click “Browse” to open it in a browser.

Step 11: Now, let’s call the API endpoint and add the name parameter to it.

 

You can now use Azure Functions to trigger code in any language with the custom handlers feature.


Last Updated : 30 Mar, 2023
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads