A Quick Look at Azure Functions

I was working on a project that uses Azure Functions. An Azure Function is an example of (the wildly misnamed) “serverless technology”. An Azure Function lives in the Cloud, accepts HTTP requests, and gives an HTTP response.

I hadn’t used Azure Functions for several months so I did a quick Hello World to see if anything had changed. First, I installed the command line tool for Azure Functions from https://www.npmjs.com/package/azure-functions-core-tools. The installer is an msi file so after I downloaded it (func-cli-x64.msi). I double-clicked on it and the install wizard ran without trouble.

Next, I created a new project named HttpHelloWorld by opening a shell, navigating to a directory where I wanted my code to live, and issued the commands:

func init --worker-runtime dotnet

func new --name HttpHelloWorld --language c# --template httptrigger

Azure Functions run on Azure, which costs money, but fortunately you can test them locally. I issued the command:

func start

The command searches the current directory for something to run, found it, and started up a local Web service (that simulates what would happen on Azure) which listens for HTTP requests.

I opened a browser and issued the request

http://localhost:7071/api/HttpHelloWorld?name=James

The Azure Function received the request and returned the response:

Hello, James. This HTTP triggered function executed successfully.

Designing and implementing an application using Azure Functions and serverless technologies has a completely different feel to it than working in a traditional computing environment. Not better or worse — just different. Ordinary Azure Functions are quite limited. A special kind, called Azure Durable Functions, are essentially class objects. They can maintain state and so they’re more useful.



The math term “function” is named after the adjective functional which means “designed to be practical and useful, rather than attractive”. Some things are purely functional, and some things are purely artistic. Here are three examples of semi-functional shoes. From Japan. Of course.


The HelloWorld template code:


public static class HttpHelloWorld
{
  [FunctionName("HttpHelloWorld")]
  public static async Task Run(
    [HttpTrigger(AuthorizationLevel.Function, "get", "post")] HttpRequest req,
    ILogger log)
  {
    log.LogInformation("C# HTTP trigger function processed a request.");

    string name = req.Query["name"];

    string requestBody = await new StreamReader(req.Body).ReadToEndAsync();
    dynamic data = JsonConvert.DeserializeObject(requestBody);
    name = name ?? data?.name;

    string responseMessage = string.IsNullOrEmpty(name)
      ? "This HTTP triggered function executed successfully. Pass a name in the" +
        " query string or in the request body for a personalized response."
      : $"Hello, {name}. This HTTP triggered function executed successfully.";

    return new OkObjectResult(responseMessage);
  }
}
This entry was posted in Miscellaneous. Bookmark the permalink.

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s