Get started with Azure Logic apps and your own API App in 5 minutes


If you have any interest in the world of Microsoft Azure, you’ll have been unable to escape the hype surrounding the new Azure App Service, especially the new kids in town; API Apps and Logic Apps.

There are plenty of demos and tutorials on these services in action and if you have not already done so, I highly recommend watching the two Azure Friday sessions with Scott Hanselman to get your head around the concepts behind Azure API apps and Logic apps:

The existing demos and tutorials are very compelling and really show the power of these new services, but sometimes you just want a very clean, simple ‘hello world’ style example to get you started, that is what I hope to achieve in this article.

We’ll create a very simple API app based on the default template. We’ll then use a logic app to make requests to the API and post them to a neat little utility called RequestBin which is great for testing and debugging REST APIs.

What you’ll need to get started

You’ll need a few things to get started with this:

1)      A Windows PC. It can be real or VM; doesn't matter, if you do not have a real machine, try an Azure VM

2)      Visual Studio 2013. Get it here: https://www.visualstudio.com/en-us/products/visual-studio-community-vs.aspx

3)      An Azure subscription. Get it here: http://azure.microsoft.com/en-gb/offers/ms-azr-0044p

4)      The Azure SDK for VS 2013. Get it here: http://azure.microsoft.com/en-us/downloads/

5)      About 5 minutes of your time. I can’t help you get that I'm afraid!

Step 1: Create a new Request Bin

http://requestb.in/ is a fantastic utility that captures and display any HTTP requests that it receives. You can go to http://requestb.in and 'Create a new ReqestBin'. This will give you a 'bin url'; grab that, you'll need it later.

Step 2: Create a new empty Logic App

In the Azure portal, create a new Logic App. The process is fairly self-explanatory, but just in case:

1)      Go to http://portal.azure.com and login

2)      Go to New > Web + Mobile > Logic App

3)      Choose a name and change the other defaults if you want, or just accept them. Be sure to take a note of the ‘App Service Plan’ name; you’ll need it later in step 5.

4)      Click Create and wait until you get a notification to say it has been created

Step 3: Create an API app

In this step, we’ll use Visual Studio to create a new API app.

We’ll just use the default ‘Azure API app’ template which returns an array of hard-coded strings. It sounds dull, but it is good enough for our purposes, dull is good when you are new to something! 🙂

1)      Open Visual Studio

2)      File > New Project > ASP.Net Web Application

3)      Choose ‘Azure API App (preview)’ as your template. If you cannot see this (or something similar), you forgot to install the SDK. Go back to ‘What you’ll need to get started’ and try again.

This gives you a very simple Web API. There is a controller called ‘values’ which has some basic hardcoded actions. You can explore this if you want, it is in /Controllers/ValuesController. We’ll be using the ‘public IEnumerable<string> Get()’ action later on to get that hard-coded array of strings (“value1” and “value2”).

Step 4: Enable Swagger UI

API apps use a metadata format called Swagger. You can learn the details of Swagger another time, for now, you just need to enable it:

1)      Open /App_Start/SwaggerConfig.cs

2)      Uncomment ‘}).EnableSwaggerUi(c =>{‘ by removing the ‘/*’ and ‘*/’ that surrounds it (it is laid out over three lines in the actual file)

Step 5: Publish your API app

You now need to publish your API app to Azure. Unusually, this is a two-step process for API apps. In the first step, you’ll provision the API app instance in Azure, secondly your publish this code to that API app.

1)      Right-click on the Project > Publish

2)      Choose ‘Microsoft Azure API Apps (Preview)’

3)      New

4)      Set the name etc however you like, but be sure to use the same ‘App Service Group’ that you created in step 2 when you created your empty logic app.

5)      Click OK. This will provision the API App instance in Azure. Keep an eye on the Output window and wait until it says “Azure API App [your name] provisioned”, it will take 2-3 minutes.

6)      Right-click on the Project > Publish (again!)

7)      Click Publish. This will actually publish your code to the API App instance you just created. Again, watch the output windows and wait until it says “Publish Succeeded”, it will take another 2-3 minutes.

Step 6: Construct your Logic App

You've done all the hard work; this is the fun bit. You’ll now add the various pieces together in your logic app and see it working.

1)      Go to http://portal.azure.com and login

2)      Browse > Choose your Logic app from the ‘recent’ section

3)      Edit

4)      Tick ‘Run this logic manually’ in the ‘Start Logic’ section. This just means you will manually run the app rather than use a recurring schedule.

5)      You should see your API app in the section on the right, click it. This will add your API App to the workflow and present the list of actions available. These actions map to the actions in your web API.

6)      Click ‘Values_Get’

7)      Click the green tick to complete the configuration

At this point your logic app will be able to perform a GET request to your API and get that array of strings (“value1” and “value2”). In the next steps we’ll use the built-in HTTP app to post this data to our Request Bin.

8)      Click the ‘HTTP’ API app on the right side

9)      Choose the ‘POST’ action

10)   In the ‘URI’ field add the ‘Bin URL’ from step 1

11)   In the ‘Body’, click the … button and choose ‘Values_Get Body[0]’. This basically means that the body of your post request will be whatever the output of the Values_Get action on the previous logic app card was.

12)   Click the green tick to complete the ‘HTTP’ card configuration. Sometime the URI does not recognise the RequestBin URI as a valid uri. If this happen just go back and try again. It is a bug in the Azure Portal.

13)   Click ‘Save’ to save the entire Logic app

14)   Wait until you see that notification that it was saved and close the Logic App edit blade

15)   Click ‘Run Now’ and watch the ‘Operations’ section to see that your app’s run completed successfully

Step 7: Bask in the glory

Your Logic should have competed now, so go back to http://requestb.in/ and you should see your request bin in the ‘history’ section on the right. If not go to http://requestb.in/[Your Request Bin ID]?inspect

You’ll see the details of your request and in the ‘Raw Body’ section you’ll see ‘value1’ which is the data that has come from your API.

This was a very simple, relatively useless example of using Azure Logic apps with your own custom API app. However I hope that this has demonstrated enough value in the platform for you to go ahead and play with more complex scenarios.

Comments (0)

Skip to main content