Modern development: creating a REST API, via CI/CD and back
Tags: beginners, devops, azure, dotnet
Published: 2021-01-04 16:39:05

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](https://github.com/features/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 [Todo App](http://todomvc.com/) 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*:

{% youtube sWgUItG2beE %}

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](https://www.youtube.com/watch?v=sWgUItG2beE&t=0s))
-   Book - Practical Azure SQL for Modern Developers ([1:34](https://www.youtube.com/watch?v=sWgUItG2beE&t=94s))
-   Session and Project description ([2:39](https://www.youtube.com/watch?v=sWgUItG2beE&t=159s))
-   Creating REST API ([8:10](https://www.youtube.com/watch?v=sWgUItG2beE&t=490s))
-   Azure SQL JSON Support ([22:45](https://www.youtube.com/watch?v=sWgUItG2beE&t=1365s))
-   Connect Azure SQL to REST API ([32:09](https://www.youtube.com/watch?v=sWgUItG2beE&t=1929s))
-   Test GET Method ([34:25](https://www.youtube.com/watch?v=sWgUItG2beE&t=2065s))
-   Dynamic Schema options ([37:35](https://www.youtube.com/watch?v=sWgUItG2beE&t=2255s))
-   Running Todo Backend API test suite ([39:45](https://www.youtube.com/watch?v=sWgUItG2beE&t=2385s))
-   Implementing Database Test with NUnit ([42:52](https://www.youtube.com/watch?v=sWgUItG2beE&t=2572s))
-   Add Database Deployment via DBUp ([50:10](https://www.youtube.com/watch?v=sWgUItG2beE&t=3010s))
-   Deploy solution using GitHub Actions ([57:54](https://www.youtube.com/watch?v=sWgUItG2beE&t=3474s))
-   Demo of complete solution ([01:05:17](https://www.youtube.com/watch?v=sWgUItG2beE&t=3917s))
-   Questions & Answers ([01:09:37](https://www.youtube.com/watch?v=sWgUItG2beE&t=4177s))

## Source Code Anyone?

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

{% github yorek/bcnet-2020 no-readme %}

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:

-   [Getting Started with DevOps for Azure SQL](https://www.youtube.com/watch?v=j7OnxOz7YDY)
-   [Using Azure Pipelines for Azure SQL Deployments](https://www.youtube.com/watch?v=G7H6HbzwAfs)

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:

{% github Azure-Samples/azure-sql-db-ci-cd no-readme %}

## 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 wrote exactly on the development and data subject:

[![practical-azure-sql-database-for-modern-developers-small](https://dev-to-uploads.s3.amazonaws.com/i/ixoe6tg2aitlk5ur6p9j.jpg)](https://www.amazon.com/gp/product/1484263693)

Enjoy!