Search icon
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Learning Azure Functions

You're reading from  Learning Azure Functions

Product type Book
Published in Sep 2017
Publisher Packt
ISBN-13 9781787122932
Pages 240 pages
Edition 1st Edition
Languages
Concepts

Chapter 9. Working with Different Languages

"Elegance is not a dispensable luxury but a factor that decides between success and failure"

– Edsger Dijkstra

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...

The Python Function App


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.

Example

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:

  1. 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:
  1. 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 request
    • QueueTrigger - Python: This trigger gets fired when a message is added to specified Azure Queue storage
  2. Select HttpTrigger - Python. Now...

The PHP Function App


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.

Example

Now we will create an Azure Function with the DNS lookup example in PHP:

  1. 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.
  2. 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:

  1. Now, give a name to the function, provide the storage account connection, and click on the Create button...

Summary


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...

lock icon The rest of the chapter is locked
arrow left Previous Chapter
You have been reading a chapter from
Learning Azure Functions
Published in: Sep 2017 Publisher: Packt ISBN-13: 9781787122932
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime}