NOTE: I will not be showing you any UI development and all of the data entry will be done through the Azure Storage Explorer.

Prerequisites

NPM and Node

Visual Studio Code

Azure Storage Emulator

Azure Storage Explorer

Knowledge of Azure Functions and developing with JavaScript in a Node Environment

The Webhooks Micro Service

We will creating our Webhooks Micro Service using Azure Functions in NodeJS.

Before we get started, we need to install some Azure Function tools to work with NodeJS.

Open a command prompt and enter the following

npm i -g azure-functions-core-tools

First let’s create a new folder af-webhook-client and within it, let’s run the following commands

func init .

Choose the node worker runtime.

Let’s create our first function

func new

Choose the Queue Trigger, the JavaScript language and choose the name, webhooks-service

Now in our local.settings.json we can define our AzureWebJobsStorage to use the development storage connection string.

We can now set our function.json inputs

In our Azure Function, we are going to define two inputs and no outputs. Our primary input will be a queue trigger and essentially, our Azure Function will fire and forget and will not need to reply back or store anything elsewhere using the output bindings.

Here, our primary input binding is the queueTrigger. We are assuming that the message within the event in our queue are going to have the following schema.

{

"userId": "",

"eventType": "",

"message": ""

}

This in turn will be what we are filtering by for our table input. We can use the filter property to build an expression within the table binding to filter the rows.

We made our partitionKey to be the userId as this will ensure that all of the webhooks for that user will be collated together. our rowId is going to be the eventType as only a single webhook callback action shall be defined for that user.

We want to be able to post to the callback our data so we will use fetch to do so. Let’s install fetch

npm i -S node-fetch

As you can see, we are grabbing our subscription from the context binding. Then we build up our payload which includes the eventId and the createAt timestamp and the message itself.

We can access additional queue item data using context.bindingData

we then try to post the data to the subscription url. If this fails, we write a message to the console.

Let’s give this a try.

Open up Azure Storage Explorer. Let’s create our queue and table storage.

Let’s add our first entry to the webhooksubscriptions table

Run your function using

func host start

We can now test our our first event. In the Azure Storage Explorer, let’s add a single event

{

"userId": "test_user",

"eventType": "document_uploaded",

"message": "my_document1"

}

Voila! You should now see…