In recent days, I have been very curious on Serverless architecture and since I love to work on .NET (C#), so choosing Azure for initial playing was more appropriate for me. But, unfortunately, Azure Function didn’t have any local development feature (until now). So, I decided to have a shot on this and share the steps.
First of all, I needed to install the preview version of visual studio 2017 (aka 15.3). You can get it from here.
And only install the Azure SDK like below.
After successful install, I needed to install the Azure Function Tools from Extensions menu.
Then I created a new project.
Not so fast. I faced some problem if I directly press the Run / Debug button. So, I figured out that I need to ‘Reinstall’ the packages.
Then I could create the function. Simply go to project, then do ‘Add New Item’.
Then, the window should appear. For testing locally without using any other Azure resource, I have choose HttpTrigger.
If you are not familiar with HttpTrigger, if we choose this type of trigger, the function will be exposed as a HTTP resource, and we can execute the code block (aka function) by requesting a HTTP call to that particular endpoint. Yes, it works like a Web API Action, but with different execution mechanism.
By default, the item template will have some code in it, like below.
The code above is self explanatory, so I am not going to describe this line by line. Just one thing to check, the same method can be accessed by two different HTTP Verb (GET, POST).
The unknown player : Azure Function CLI
Then when I ran the application, the debugger said that it needs to install Azure Functions CLI Tools. I had no idea what it was, but I agreed to let he debugger install it. So, I saw a window like below.
Then I googled about this, and found it could be installed through npm as well. But anyway, I had it installed. Then, I could run the application and the output was like below.
Please check the endpoint. This is the default endpoint / URL of the hosted function. Our newly created function has the endpoint like below.
Test the function
To test the function, I used Telerik’s Fiddler.
Serverless architecture is getting momentum in modern software development. Beside of doing the above ‘Hello World’ thing, what else can we do using Azure Function?
In the next post I will show how can we execute some intensive database operation using Azure Function.
If you have any questions about Azure / Cloud please feel free to send me message in our Facebook page Code Coopers. You can send me email directly at firstname.lastname@example.org or email@example.com.