Creating an HttpStart function in the Orchestrator client

Perform the following steps:

  1. Create a new Durable Functions HTTP starter function by choosing Durable Functions in the Scenario drop-down menu, and click on the Durable Functions HTTP starter, which opens a new tab, shown as follows. Let's create a new HTTP function named HttpStart:

  1. Soon after, you will be taken to the code editor. The following function is a HTTP trigger which accepts the name of the Function that needs to be executed along with the input. It uses the StartNewAsync method of the DurableOrchestrationClient object to start the Orchestration:
      #r "Microsoft.Azure.WebJobs.Extensions.DurableTask"
#r "Newtonsoft.Json"

using System.Net;

public static async Task<HttpResponseMessage> Run(
HttpRequestMessage req,
DurableOrchestrationClient starter,
string functionName,
ILogger log)
{
// Function input comes from the request content.
dynamic eventData = await req.Content.ReadAsAsync<object>();
string instanceId = await starter.StartNewAsync(functionName,
eventData);

log.LogInformation($"Started orchestration with ID = '{instanceId}'.");

return starter.CreateCheckStatusResponse(req, instanceId);
}
  1. Navigate to the Integrate tab and click on Advanced editor, as shown in the following screenshot:
  1. In the Advanced editor, the bindings should be similar to the following. If not, replace the default code with the following code:
        {
"bindings":
[
{
"authLevel": "anonymous",
"name": "req",
"type": "httpTrigger",
"direction": "in",
"route": "orchestrators/{functionName}",
"methods": [
"post",
"get"
]
},
{
"name": "$return",
"type": "http",
"direction": "out"
},
{
"name": "starter",
"type": "orchestrationClient",
"direction": "in"
}
]
}
The HttpStart function works like a gateway for invoking all the functions in the function app. Any request you make using the https://<durablefunctionname>>.azurewebsites.net/api/orchestrators/{functionName} URL format will be received by this HttpStart function. This function will take care of executing the Orchestrator function, based on the parameter available in the {functionName} route parameter. All of this is possible with the route attribute, defined in function.json of the HttpStart function.