A Website Without Servers – Using Azure Functions: Part 5, Pulling Wardrobe Data


| October 26, 2017 | in

Previously on Using Azure Functions, we set up a very simple Angular website. This week, we are going to set up an Azure Function that pulls some wardrobe data from an Azure Cosmos database.

Why not just build the wardrobe into the app? Well I’m hoping to update the wardrobe by season, so having to do a full release just to update that part of it will be pretty annoying. And this is the “Over Engineered Fashion” application we are working on. This is a chance to use many Azure features, and maybe overdo it a little 🙂

First, we must create an Azure Cosmos DB.

Create a collection.

After we create the collection, we can create the record for our first catalog.

Same code below:

Now that we have a document database, we will link our Azure Function to it. web-based text editor is going to suck, right?

One awesome thing about Azure Functions is you can call code in other .NET assemblies. And if you think about it, a .NET assembly can easily be tested on the ground before shipping up to Azure. So instead of writing a bunch of code in a web page, we’ll just deploy a DLL that we have tested on the ground.

I’m only going to be creating a single accessor called a “wardrobe accessor”. In a real architecture, we like to have managers –> accessors. For this test application, we are only going to have an accessor.

We will create a very simple VS solution where we can test our code before pushing it to the cloud. We will create two projects, a test client (console app) and a class library (accessors).

Then we just need to write our accessors and some code to test them.

First, we will create our contract for the Accessor:

Then we will create a service that implements the accessor:

Next, we will create a factory that will create an instance of our service.

Then we need to write a test client so we can test this application.

Now that we have code that is solid, we will deploy it to an Azure Function. But that is our next episode…