Durable Functions - Patterns - Async HTTP APIs

Introduction

  • This is a series of articles to keep our hands dirty on Durable Functions and their patterns in detail.
  • Please refer to my previous article to understand the basics of durable functions.
  • In this article, we would cover the Async HTTP APIs pattern.

It will cover the following things,

  • Application Patterns
  • Pre-requisites
  • What is the Async HTTP APIs pattern?
  • Hands-on Lab – Create durable function using Async HTTP APIs pattern in C#.
  • Hands-on Lab – Deploy a durable function using Async HTTP APIs pattern on Azure.

Application patterns

The following application patterns can benefit from Durable Functions,

  • Chaining
  • Fan-out/fan-in
  • Async HTTP APIs(COVERED in this article)
  • Monitoring
  • Human interaction
  • Aggregator (stateful entities)

Pre-requisites

These are pre-requisites to start working on durable functions,

  • An Azure pay-as-you-go account enabled
  • Install Visual Studio 2019
  • Install Azure Storage Emulator

What is Async HTTP APIspattern?

  • In the Async HTTP APIs pattern, we address the problem of coordinating the state of long-running operations with external clients. A common way to implement this pattern is by having an HTTP endpoint trigger the long-running action. Then, redirect the client to a status endpoint that the client polls to learn when the operation is finished.
  • Durable Functions provides built-in support for this pattern, simplifying or even removing the code you need to write to interact with long-running function executions. 

Durable Functions - Patterns - Async HTTP APIs

Hands-on Lab – Create durable function using Async HTTP APIs pattern in C#

Steps to be followed,

  • Open VS 2019 and create a project.
  • Choose Azure function template and create a directory.

    Durable Functions - Patterns - Async HTTP APIs
     
  • Choose durable functions orchestration template.

    Durable Functions - Patterns - Async HTTP APIs
     
  • Once the application has been created, we would see three functions where we can see three functions,
    • Function1 – Main functionality function which internally calls Function1_Hello multiple times and returns the result
    • Function1_Hello – Intermediate function gets called from Function1 multiple times, responsible for manipulating the input and generate output
    • Function1_HttpStart – Function in the form of http trigger which is responsible for initiating Function1 and gather the response

      Durable Functions - Patterns - Async HTTP APIs
       
  • Run (F5) the application and see all the functions that have been listed here.

    Durable Functions - Patterns - Async HTTP APIs
     
  • In this above example, you see an HTTP URL that allows instantiating the orchestration,
  • Copy the URL of Function1_HttpStart and run it in the browser.

    Durable Functions - Patterns - Async HTTP APIs
     
  • Copy the URL of statusQueryGetUri (GET URL) and run it in the browser.

    Durable Functions - Patterns - Async HTTP APIs

Here, you can see the response from Function1 which got instantiated from Function1_HttpStart with the desired output, and HTTP APIs pattern is used to extract the status of running function_1, so any HTTP trigger that can be used to interrupt or initiate the main function.

Hands-on Lab – Deploy a durable function using Async HTTP APIs pattern on Azure

Steps to be followed,

Right-click on the function and click on publish and choose target as Azure.

Durable Functions - Patterns - Async HTTP APIs

Choose an option as Azure function app (Windows).

Durable Functions - Patterns - Async HTTP APIs

Create/choose the new/existing resource group and resource for azure function deployment.

Durable Functions - Patterns - Async HTTP APIs

Click on Finish and let it get published and once published, go to the Azure portal and test the function app using the steps which we did in the above steps while creating durable functions

This is a basic example of Async HTTP APIs, where an HTTP trigger is used to extract the status of the instance

There are multiple other patterns that represent where to use duration functions, stay tuned for the next series of articles to get a hang of it.

Happy learning!


Similar Articles