Better Programming

Advice for programmers.

Follow publication

Member-only story

Writing Serverless Business Logic With Hasura Actions and Azure Functions

Tobias Streng
Better Programming
Published in
8 min readFeb 2, 2022

--

Photo by Sigmund on Unsplash

Using Hasura has many advantages. You have a central gateway, through which you can connect to many backend services at once, including SQL databases, GraphQL endpoints, or REST endpoints, and everything is queryable with the GraphQL language.

With Hasura Actions you have the possibility to implement custom logic, that can be called by a GraphQL Mutation or Query. You will have to set up a REST endpoint for this, which needs to be reachable by Hasura. You have the choice to either set up a server, which is running all the time, or simply set up a serverless function, which does not waste resources, while it is not in use.

Of course, each of those variants has its up and downsides, but this is another topic, which I will cover in the future. In this showcase I will present you, how to set up an Azure Function, that can handle calls from Hasura and will function as your backend logic. I will use .NET 6 and C# for this example, however, you are free to choose another language of course.

If you have not yet worked with Hasura, here is another article of mine, which covers setting up a Hasura demo and automatically generating typescript code for a GraphQL client in Angular.

Overview

Architecture Overview

The graphic above shows the architecture of this showcase. Hasura is hosted on the Amazon Web Services Cloud, which is the default environment, when you set up a Hasura Cloud. The PostgreSQL database and our serverless Azure Functions App is hosted on the Microsoft Azure Cloud.

The code for the Azure Functions App of this showcase can be found on my Github here.

Initial Setup of the Azure Function

Setting up an Azure Function is straightforward. If you do not have an Azure account yet, I advise you to sign up and try a few things by yourself. Most of the Azure cloud computing environment can be…

--

--

Tobias Streng
Tobias Streng

Written by Tobias Streng

Senior Software and Cloud Solutions Architect

Write a response