The Async HTTP APIs pattern addresses the coordination of states in long-running operations that are available to client consumers. On the graph, from an HTTP Start trigger some DoWork is executed, and a client can query an API to GetStatus, to identify whether the operation is running, or it has finished.
Running the flow
Using the Visual Studio quickstart sample this can be easily demoed. Create a new solution using the template:
The project is created in a single file Function1.cs:
usingSystem.Collections.Generic;usingSystem.Net.Http;usingSystem.Threading.Tasks;usingMicrosoft.Azure.WebJobs;usingMicrosoft.Azure.WebJobs.Extensions.DurableTask;usingMicrosoft.Azure.WebJobs.Extensions.Http;usingMicrosoft.Azure.WebJobs.Host;usingMicrosoft.Extensions.Logging;namespaceDurableFunctionsAsyncHTTPAPIsPattern{publicstaticclassFunction1{[FunctionName("Function1")]publicstaticasyncTask<List<string>>RunOrchestrator([OrchestrationTrigger]IDurableOrchestrationContextcontext){varoutputs=newList<string>();// Replace "hello" with the name of your Durable Activity Function.
outputs.Add(awaitcontext.CallActivityAsync<string>("Function1_Hello","Tokyo"));outputs.Add(awaitcontext.CallActivityAsync<string>("Function1_Hello","Seattle"));outputs.Add(awaitcontext.CallActivityAsync<string>("Function1_Hello","London"));// returns ["Hello Tokyo!", "Hello Seattle!", "Hello London!"]
returnoutputs;}[FunctionName("Function1_Hello")]publicstaticstringSayHello([ActivityTrigger]stringname,ILoggerlog){log.LogInformation($"Saying hello to {name}.");return$"Hello {name}!";}[FunctionName("Function1_HttpStart")]publicstaticasyncTask<HttpResponseMessage>HttpStart([HttpTrigger(AuthorizationLevel.Anonymous,"get","post")]HttpRequestMessagereq,[DurableClient]IDurableOrchestrationClientstarter,ILoggerlog){// Function input comes from the request content.
stringinstanceId=awaitstarter.StartNewAsync("Function1",null);log.LogInformation($"Started orchestration with ID = '{instanceId}'.");returnstarter.CreateCheckStatusResponse(req,instanceId);}}}
Join the conversation! Share your thoughts and connect with other readers.