liveBook · Manning

HTTP trigger

As explained in Microsoft Azure in Action

An HTTP trigger is a workflow or function trigger that starts execution when it receives an HTTP request.

An HTTP trigger starts a Function or workflow when its HTTP endpoint receives a request. It is useful when a caller needs to start work through an API rather than wait for an event such as a new blob. An Azure Function must have exactly one trigger; without one, it has no signal to run. section 8.2.1 section 8.4.5

For an Azure Function, the request arrives as an HttpRequest parameter. It can carry ordinary HTTP details, including the host and referrer. The HttpTrigger declaration also sets the authorization level and permitted methods: the example accepts GET and POST. Anonymous access requires no authentication, so choose it deliberately rather than by habit. section 8.2.1 section 8.2 section 8.2.2

[FunctionName("ProcessNFT")]
public static void Run(
    [HttpTrigger(AuthorizationLevel.Anonymous, 
"get", "post", Route = "nft/{nftid}")] HttpRequest req,    #1
    [Blob("originalnfts/{nftid}", FileAccess.Read)] 
Stream nftImage,    #2
    [Blob("copynfts/{nftid}", FileAccess.Write)] 
Stream nftSmall)    #3
{
    IImageFormat format;

    using (Image<Rgba32> input = 
Image.Load<Rgba32>(nftImage, out format))    #4
    {
        input.Mutate(x => x.Resize(320, 200));    #5
        input.Save(nftSmall, format);    #6
    }
}

The Function declaration places HttpTrigger on the request parameter and uses a route containing an NFT ID. Separate Blob bindings read the original image and write the resized copy; they do not start the Function. section 8.2.2

Put a Logic App behind an API

Suppose an API call should post an NFT image. A Logic App started by a blob trigger cannot be connected to API Management as that endpoint: it needs an HTTP endpoint. Create a second Logic App with an HTTP trigger, accept the NFT ID in a query string, retrieve the image from Blob Storage, post the tweet, and connect the endpoint to API Management. Consider authentication for the incoming request, too. section 8.4.5

How Microsoft Azure in Action covers it

How deep it goes
Explains Function invocation and request data, shows trigger configuration, and sets a Logic App integration exercise rather than walking through its solution.
Examples
Uses a GET/POST NFT-processing Function and a proposed HTTP-triggered Logic App that retrieves an image and posts a tweet.
What it assumes
Introduces triggers from their basic purpose while assuming familiarity with HTTP requests for the API integration exercise.
What you can do after
Operate/configure it by choosing an HTTP trigger, permitted methods, route, and authorization level; plan an HTTP endpoint for API Management.
How it connects
Connects Azure Functions, Logic Apps, API Management, authentication, Blob Storage triggers, and Blob bindings.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Microsoft Azure in Action. The section links point to the parts of the book it draws on.