In my previous post, I showed how did I installed and ran a simple Azure Function in my local environment using Visual Studio 2017 (15.3). In this post, I will show how can we create a function which can access the Database Server, fetch the model by Id and Generate a Barcode Image of the model’s barcode using a Third Party Library (Aspose.Barcode). Let’s start.
NOTE: Whole project can be found in github https://github.com/foyzulkarim/Azure. Please mark star the repo and if you have any question, please let me know.
First we will create a new Azure Function App and update the packages. Detailed steps are shown in the previous post. I highly recommend you to check that before proceeding this part. 🙂
Then we will add two new function. Like below, we will choose HttpTriggerWithParameter for both of them. Let’s name these DownloadBarcodeByProductId and DownloadBarcodeByText.
Then we will add our required barcode generation code and logics.
Another thing to note is, we need to embed the connection string into the code. I couldn’t find any reference of using App.config / Web.config in this type of project yet.
Now lets go back to the actual function codes. We will accept only GET request and we define our preferred route for accessing the function. And we accept the parameter as string values. In one function we accept the id and fetch the product’s data from database. In the other function, we accept the barcode and text values.
Both function will then call to the BarcodeImageHandler’s method.
The full project can be found in the Github https://github.com/foyzulkarim/Azure
If you find this interesting, or have any question, feel free to knock me in my Facebook Page Code Coopers or email me at firstname.lastname@example.org
Now lets test the app.
If we run the application first time, it requires the permission of accessing network, like below.
Then, we can see there are two endpoints created. You can see the endpoints at the bottom of the console screen.
And if we request the endpoints using fiddler, the output should come accordingly.
In the next part, I will try to focus on publishing the function to Azure and how can we apply security mechanism on it.