January 4th, 2021

Modern development: creating a REST API, via CI/CD and back

Davide Mauri
Principal Product Manager

devops lifecycle

If you are about to start your next project, which will presumably involve the creation of a backend REST API that will interact with data stored in a database, you should do so by using a modern approach and apply DevOps principles right from the start.

For doing that, GitHub Actions are an amazing tool to build a CI/CD pipeline. You know that already, I’m sure. (If not, make sure you take a look here: GitHub Actions).

Now, I could spend hours and hours on the subject, but I guess the best way to show that is with live coding video, so that you I’ll be able to see how to that with your own eyes.

The solution also shows how to put the database, Azure SQL in my case, in the CI/CD pipeline, so that everything can be deployed-tested-released using a streamlined process.

Let’s see how, with the aid of a real-world project: the well known To-do App which is just great as a learning tool.

Learning via Live Coding

I did a presentation for the BC .Net User Group on this topic not so long ago, in form live coding session where you can see how to create a REST API from scratch using an integrated CI/CD pipeline, with deployment and unit-testing:

From Azure SQL to REST on YouTube

As any live coding session is a bit long so I created placeholder for all the interesting parts so it’s easy to jump to the section you are interested in.

  • Intro (0:00)
  • Book – Practical Azure SQL for Modern Developers (1:34)
  • Session and Project description (2:39)
  • Creating REST API (8:10)
  • Azure SQL JSON Support (22:45)
  • Connect Azure SQL to REST API (32:09)
  • Test GET Method (34:25)
  • Dynamic Schema options (37:35)
  • Running Todo Backend API test suite (39:45)
  • Implementing Database Test with NUnit (42:52)
  • Add Database Deployment via DBUp (50:10)
  • Deploy solution using GitHub Actions (57:54)
  • Demo of complete solution (01:05:17)
  • Questions & Answers (01:09:37)

Source Code Anyone?

Of course there is a GitHub repo ready for you to play with:

https://github.com/yorek/bcnet-2020

Fully documented and fully working: you can use it to kickstart your next project.

More info on the database lifecycle

Putting code in a CI/CD pipeline is quite easy and doesn’t require any specific approach. For a database it’s a bit different since besides code, there is also the data that we must consider. There are a couple of possible ways to include the database in the CI/CD pipeline, depending on which development approach you prefer: 

  • Migration-based (code-first or database-first) 
  • State-based 

The differences between the two are well explained in these two videos: 

I really recommend watching them as they are full of interesting learnings.

I’m a newbie, this is way too complex!

I totally understand. REST API, JSON, Database, DevOps, CI/CD, Pipelines, C# or Python…there’s a lot to learn. For this reason, I have also created a repository focused only on the data aspect so that you can start easy understanding that part:

https://github.com/Azure-Samples/azure-sql-db-ci-cd

Master your data

As you may have realized, even if you are a back-end or full-stack developer, data is important and thus dealing with it appropriately is definitely a must. If you liked this article and the video, I’m sure you’ll love this book I (co-)wrote exactly on the development and data subject:

Image practical azure sql database for modern developers small

Enjoy!

Author

Davide Mauri
Principal Product Manager

Principal Product Manager in Azure SQL, with a career in IT spanning since 1997, earning the prestigious Data Platform MVP status for 12 consecutive years. Currently, he serves as the Principal Product Manager for Azure SQL Database, focusing on developers and AI.

0 comments

Discussion are closed.