A simple API using Azure Functions

At Build 2017, I learnt quite a bit on Azure functions, which I’d like to demonstrate to you at Open Night.

I’ll be using Azure Cognitive services to create a simple web app that recognizes and groups faces found in uploaded photos.

As a bonus you will be able to upload a photo and find other photos with similar faces. The finished demo is on github.


If you want to get this running you’ll need an Azure account (a free trial account will do just fine) and a Windows machine running Visual Studio 2017 Preview 3 with the latest Azure Functions tooling preview installed. Instructions for installing and using the tooling are here.

Getting started

First, let’s define a few simple endpoints that we’ll need:

  • POST /api/faces This endpoint is to upload a picture containing faces
  • GET /api/faces This endpoint lists the unique faces that have been recognized
  • GET /api/faces/{id} This endpoint lists all photos for a given face id
  • POST /api/faces/similar This endpoint accepts a photo and returns a list
    of faces found in it

In addition to these we’ll have a function that monitors a Azure Blob Storage folder for new images. It is this function that will do most of the work

Defining functions

With the new functions tooling comes a new way of defining functions and their inputs. The previous method of defining a function.json with all the data is gone. Now the metadata is defined in code and the function.json files are generated at build time. This is a significant improvement over the previous tooling.

In addition, functions can now be run and debugged in Visual Studio with very little effort. In fact, it works the same way that any other dotnet project does: click the run button and everything just works. In reality there are a few issues with the preview tooling but these should be sorted before final release.

API endpoints

I’ll go into a bit of detail on the image upload endpoint as that contains most of the interesting stuff.

The full code for this method is on Github. The other API functions are pretty simple and can be seen on Github.

Face detection

Face detection is done in a background task that gets triggered by an image being uploaded to the storage folder in the API function above.

The full code for this method is on Github.

At this point we now have a functional API for uploading images and recognizing faces. The only thing that is left now is building a frontend for this – an exercise I’ll leave to you for now 😉

Web Design BangladeshWeb Design BangladeshMymensingh