Press "Enter" to skip to content

Integrate Azure functions with K2


Azure Functions is a serverless application platform. It allows developers to host business logic that can be executed without provisioning infrastructure. Functions provides intrinsic scalability and you are charged only for the resources used. In the article below I will show how to integrate Azure functions with REST ServiceBroker in K2.

Azure functions are event driven, which means they run in response to an event or triggers. Azure supports triggers for different services, including HTTP. It starts a function with HTTP request. I will create a simple Azure function with an HTTP trigger.

1. Create a function app

Sign into the Azure portal . Select the Create a resource button found on the upper left-hand corner of the Azure portal, and then select Get started > Serverless Function App to open the Function App Create blade. Alternatively, you can use the Compute > Function App option, which will open the same blade.

Azure portal, creating function app.

Then you can fill in the required fields, selecting or entering the appropriate data. I selected JavaScript as a Runtime Stack.

2. Add a function to our function app

Azure provides templates that help you get started building functions. In this demo, we’ll use the HttpTrigger template.

I will change the standard code snippet of the function with the following one, so that the REST ServiceBroker can process JSON in response:

3. Get the API key

HTTP triggers let you use API keys to block unknown callers by requiring the key to be present on each request. When you create a function, you select the authorization level. By default, it’s set to “Function”, which requires a function-specific API key, but it can also be set to “Admin” to use a global “master” key, or “Anonymous” to indicate that no key is required. You can also change the authorization level through the function properties after creation.

The function and master keys are in the Manage section when the function is expanded.

azure function api key

Since we specified “Function” when we created this function, we will need to supply the key when we send the HTTP request. You can send it as a query string parameter named code, or as an HTTP header (preferred) named x-functions-key. In the next step I will show you the second option.

4. Create REST Service Instance

Now we can create a Service Instance for the REST ServiceBroker in K2. In order to consume Azure functions and integrate with REST ServiceBroker, you will have to send the API key with every request. Therefore, we will use the Default HTTP Request Headers service keys, when configuring the REST Service Instance. Also we need a swagger file. You can find the swagger file and the default HTTP Request Headers json below.

In the end your Service Instance definition can look like this:

Service Instance definition.

5. Test the results

Now you can generate the SmartObjects and test your integration of Azure functions with K2 REST ServiceBroker:

azure function test

If you navigate to the Monitor dashboard of your function on the Azure portal, you’ll see that the requests have been logged to Application Insights.

Azure Monitoring example

I hoped, I managed to demonstrate, how to integrate azure functions with K2. Azure functions is a great way to add hosted services to your solution that can scale and grow with your business. You focus on the code using the language of your choice, and Azure manages the infrastructure.

Leave a Reply

Your email address will not be published. Required fields are marked *

4 × five =