Chapter 9. Working with Different Languages
"Elegance is not a dispensable luxury but a factor that decides between success and failure"
In this chapter, we will explore Azure Function with other languages. Up to now we have seen examples of Azure Function in JavaScript.
We can write Azure Functions in many languages such as C#, Python, F#, PHP, and JavaScript.
In this chapter, we will write Azure Functions in the following languages:
- The Python Function App
- The PHP Function App
Python as an object-based subset is roughly equivalent to JavaScript. Like JavaScript, Python supports a programming style that uses simple functions and variables without engaging in class definitions. Python, on the other hand, supports writing much larger programs and better code reuse through a true object-oriented programming style, where classes and inheritance play an important role. Python has built-in list and dictionary data structures, which can be used to construct fast runtime data structures...
Let's create a Python Function in Azure App. We already created Azure App in the previous chapter.
Python is still in the experimental phase, so we don't have much of an option as of now.
Now, we will create a Python Function and learn how to install and use third-party modules.
We will create an HTTP request API which gives a weather report in JSON format in response. In this example, we will use Google Weather API, which is open source:
- Log into the Azure Portal and create Azure App. We have created Azure App in the previous chapter. Now we will create the function. Click on the
+
sign and select the language, as shown in the following screenshot:
- There are only two options available for us, that is
HttpTrigger - Python
and QueueTrigger - Python
:
HttpTrigger - Python
: This trigger gets fired whenever it receives an Http requestQueueTrigger - Python
: This trigger gets fired when a message is added to specified Azure Queue storage
- Select
HttpTrigger - Python
. Now...
Let's create a PHP Function in Azure App. We already created Azure App in the previous chapter.
PHP is also still in the experimental phase, so we don't have much of an option as of now.
Now we will create an Azure Function with the DNS lookup example in PHP:
- Log into Azure Portal and click on
Azure Function App
. We already created Azure Function App in the previous chapter, so now we will create the Azure Function. - Click on the + sign and then select the coding language, as shown in the following screenshot:
By default, PHP gives the template that fetches the entities from a storage table when it receives the HTTP request.
The code for fetching a data from the storage table is already there in PHP. We can directly use it. However, in this example, we will not use the storage table. We will write code for DNS lookup.
This allows us to create only the HTTP GET
request:
- Now, give a name to the function, provide the storage account connection, and click on the
Create
button...
This is the last chapter and we have finished our journey with Azure Functions.
We started our journey with a discussion of serverless architecture with the evolution of cloud computing and we discussed in detail IaaS and PaaS.
After that we discussed Azure Functions and looked at the differences between Web App AWS Lambda and Azure Functions. We created our first function that processed a photograph and created a thumbnail. We discussed the architecture of a trigger and different types of triggers available in Azure.
In the middle of our journey, we learned about binding with the Azure Function and Webhook. After that we created a real-life example of an Azure Function and we configured Continuous Integration using the Build definition and Continuous Delivery using the Release definition.
At the end of our journey, we covered how to monitor a Functions App using the available monitoring in the Function App itself.
In this chapter we looked at other languages for writing code in Azure...