Monday 19 March 2018

How to convert existing web api to azure functions using azure functions

  1. Install Node js
  2. Install npm package, run the command “ npm i -g azure-functions-cli “ in command prompt
  3. Note Installation path of azure function cli. eg: ‘C:\Users\usrname\AppData\Roaming\npm\node_modules\azure-functions-cli’ , usrname represents your login name.

 In this blog, we will use the sample available in the GitHub. It is simple webapi application that has value
 controller and you can access the value controller in the http://localhost:xxxx/api/values

Step1: Create a empty Web API application with the name “MigratedAzurefunction”

Step 2: Install the below nuget packages in the package manager console to the MigratedAzurefunction project

Install-Package Microsoft.Azure.WebJobs -Version 2.0.0

Step 3: Create two folders named GetValuesHttpTrigger and PostValuesHttpTrigger and 
add file named function.json to the both the folders.

Step 4: Create a class called “GetValuesHttpTrigger” and add the below content.

Step 5: Create a class called “PostValuesHttpTrigger” and add the below content.

    Step 6: Add the below contents to the GetValuesHttpTrigger’s function.json

  Step 7: Add the below contents to the PostValuesHttpTrigger’s function.json

        Step 8: Create a file named host.json with contents below.

Step 9: Create a file named “appsettings.json” with content below.

Step 10: Setting up the properties of the azure function project, so we can debug and test in local.
  •  Right click on “MigratedAzurefunction” project and then click properties and navigate to Web. 
  •  Select the Start external program. Enter the azure-functions-cli path of func.exe.     Eg:- C:\Users\usrname\AppData\Roaming\npm\node_modules\azure-functions-cli\bin\func.exe
  • In Command Line argument, enter “host start”
  • In Working directory, enter the path of your “MigratedAzurefunction” E:\Karthik\Webinar-MigrateWebAPI2Azfunc\MigrateWebAPIApp\MigratedAzurefunction

Step 10: Debug the project

Step 11: Get the url from the command window that opens

Step 11: Use the postman to test the result. 

If you are using the github source code provided above. Then you should install the azure storage emulator and make sure u have started it.

Build Bot using LUIS