{"id":796,"date":"2021-01-04T07:00:35","date_gmt":"2021-01-04T15:00:35","guid":{"rendered":"https:\/\/devblogs.microsoft.com\/azure-sql\/?p=796"},"modified":"2021-01-01T17:00:12","modified_gmt":"2021-01-02T01:00:12","slug":"modern-development-creating-a-rest-api-via-ci-cd-and-back","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/azure-sql\/modern-development-creating-a-rest-api-via-ci-cd-and-back\/","title":{"rendered":"Modern development: creating a REST API, via CI\/CD and back"},"content":{"rendered":"<p><a href=\"https:\/\/devblogs.microsoft.com\/azure-sql\/wp-content\/uploads\/sites\/56\/2021\/01\/devops.png\"><img decoding=\"async\" class=\"aligncenter size-large wp-image-799\" src=\"https:\/\/devblogs.microsoft.com\/azure-sql\/wp-content\/uploads\/sites\/56\/2021\/01\/devops-1024x428.png\" alt=\"devops lifecycle\" width=\"640\" height=\"268\" srcset=\"https:\/\/devblogs.microsoft.com\/azure-sql\/wp-content\/uploads\/sites\/56\/2021\/01\/devops-1024x428.png 1024w, https:\/\/devblogs.microsoft.com\/azure-sql\/wp-content\/uploads\/sites\/56\/2021\/01\/devops-300x125.png 300w, https:\/\/devblogs.microsoft.com\/azure-sql\/wp-content\/uploads\/sites\/56\/2021\/01\/devops-768x321.png 768w, https:\/\/devblogs.microsoft.com\/azure-sql\/wp-content\/uploads\/sites\/56\/2021\/01\/devops-1536x642.png 1536w, https:\/\/devblogs.microsoft.com\/azure-sql\/wp-content\/uploads\/sites\/56\/2021\/01\/devops-2048x856.png 2048w\" sizes=\"(max-width: 640px) 100vw, 640px\" \/><\/a><\/p>\n<p>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.<\/p>\n<p>For doing that, GitHub Actions are an\u00a0<em>amazing<\/em>\u00a0tool to build a CI\/CD pipeline. You know that already, I&#8217;m sure. (If not, make sure you take a look here:\u00a0<a href=\"https:\/\/github.com\/features\/actions\">GitHub Actions<\/a>).<\/p>\n<p>Now, I could spend hours and hours on the subject, but I guess the best way to show that is with\u00a0<em>live coding<\/em>\u00a0video, so that you I&#8217;ll be able to see how to that with your own eyes.<\/p>\n<p>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.<\/p>\n<p>Let&#8217;s see how, with the aid of a real-world project: the well known\u00a0<a href=\"http:\/\/todomvc.com\/\">To-do App<\/a>\u00a0which is just great as a learning tool.<\/p>\n<h2>Learning via Live Coding<\/h2>\n<p>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\u00a0<em>and unit-testing<\/em>:<\/p>\n<p><a href=\"https:\/\/youtu.be\/sWgUItG2beE\"><img decoding=\"async\" class=\"aligncenter size-large wp-image-798\" src=\"https:\/\/devblogs.microsoft.com\/azure-sql\/wp-content\/uploads\/sites\/56\/2021\/01\/from-azure-sql-to-rest-youtube-1024x586.jpg\" alt=\"From Azure SQL to REST on YouTube\" width=\"640\" height=\"366\" srcset=\"https:\/\/devblogs.microsoft.com\/azure-sql\/wp-content\/uploads\/sites\/56\/2021\/01\/from-azure-sql-to-rest-youtube-1024x586.jpg 1024w, https:\/\/devblogs.microsoft.com\/azure-sql\/wp-content\/uploads\/sites\/56\/2021\/01\/from-azure-sql-to-rest-youtube-300x172.jpg 300w, https:\/\/devblogs.microsoft.com\/azure-sql\/wp-content\/uploads\/sites\/56\/2021\/01\/from-azure-sql-to-rest-youtube-768x440.jpg 768w, https:\/\/devblogs.microsoft.com\/azure-sql\/wp-content\/uploads\/sites\/56\/2021\/01\/from-azure-sql-to-rest-youtube-1536x879.jpg 1536w, https:\/\/devblogs.microsoft.com\/azure-sql\/wp-content\/uploads\/sites\/56\/2021\/01\/from-azure-sql-to-rest-youtube-2048x1172.jpg 2048w\" sizes=\"(max-width: 640px) 100vw, 640px\" \/><\/a><\/p>\n<p>As any live coding session is a bit long so I created placeholder for all the interesting parts so it&#8217;s easy to jump to the section you are interested in.<\/p>\n<ul>\n<li>Intro (<a href=\"https:\/\/www.youtube.com\/watch?v=sWgUItG2beE&amp;t=0s\">0:00<\/a>)<\/li>\n<li>Book &#8211; Practical Azure SQL for Modern Developers (<a href=\"https:\/\/www.youtube.com\/watch?v=sWgUItG2beE&amp;t=94s\">1:34<\/a>)<\/li>\n<li>Session and Project description (<a href=\"https:\/\/www.youtube.com\/watch?v=sWgUItG2beE&amp;t=159s\">2:39<\/a>)<\/li>\n<li>Creating REST API (<a href=\"https:\/\/www.youtube.com\/watch?v=sWgUItG2beE&amp;t=490s\">8:10<\/a>)<\/li>\n<li>Azure SQL JSON Support (<a href=\"https:\/\/www.youtube.com\/watch?v=sWgUItG2beE&amp;t=1365s\">22:45<\/a>)<\/li>\n<li>Connect Azure SQL to REST API (<a href=\"https:\/\/www.youtube.com\/watch?v=sWgUItG2beE&amp;t=1929s\">32:09<\/a>)<\/li>\n<li>Test GET Method (<a href=\"https:\/\/www.youtube.com\/watch?v=sWgUItG2beE&amp;t=2065s\">34:25<\/a>)<\/li>\n<li>Dynamic Schema options (<a href=\"https:\/\/www.youtube.com\/watch?v=sWgUItG2beE&amp;t=2255s\">37:35<\/a>)<\/li>\n<li>Running Todo Backend API test suite (<a href=\"https:\/\/www.youtube.com\/watch?v=sWgUItG2beE&amp;t=2385s\">39:45<\/a>)<\/li>\n<li>Implementing Database Test with NUnit (<a href=\"https:\/\/www.youtube.com\/watch?v=sWgUItG2beE&amp;t=2572s\">42:52<\/a>)<\/li>\n<li>Add Database Deployment via DBUp (<a href=\"https:\/\/www.youtube.com\/watch?v=sWgUItG2beE&amp;t=3010s\">50:10<\/a>)<\/li>\n<li>Deploy solution using GitHub Actions (<a href=\"https:\/\/www.youtube.com\/watch?v=sWgUItG2beE&amp;t=3474s\">57:54<\/a>)<\/li>\n<li>Demo of complete solution (<a href=\"https:\/\/www.youtube.com\/watch?v=sWgUItG2beE&amp;t=3917s\">01:05:17<\/a>)<\/li>\n<li>Questions &amp; Answers (<a href=\"https:\/\/www.youtube.com\/watch?v=sWgUItG2beE&amp;t=4177s\">01:09:37<\/a>)<\/li>\n<\/ul>\n<h2>Source Code Anyone?<\/h2>\n<p>Of course there is a GitHub repo ready for you to play with:<\/p>\n<p><a href=\"https:\/\/github.com\/yorek\/bcnet-2020\">https:\/\/github.com\/yorek\/bcnet-2020<\/a><\/p>\n<p>Fully documented and fully working: you can use it to kickstart your next project.<\/p>\n<h2>More info on the database lifecycle<\/h2>\n<p><span data-contrast=\"auto\">Putting code in a\u00a0<\/span><span data-contrast=\"auto\">CI\/CD<\/span><span data-contrast=\"auto\">\u00a0pipeline is quite easy and\u00a0<\/span><span data-contrast=\"auto\">doesn&#8217;t<\/span><span data-contrast=\"auto\">\u00a0require any specific approach. For a database\u00a0<\/span><span data-contrast=\"auto\">it&#8217;s<\/span><span data-contrast=\"auto\">\u00a0a bit different since besides code, there is also the data that we must consider. There are\u00a0a couple\u00a0of\u00a0<\/span><span data-contrast=\"auto\">possible ways<\/span><span data-contrast=\"auto\">\u00a0to include the database in the CI\/CD pipeline, depending on which development approach you prefer:<\/span><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335559739&quot;:160,&quot;335559740&quot;:257}\">\u00a0<\/span><\/p>\n<ul>\n<li data-leveltext=\"\uf0b7\" data-font=\"Symbol\" data-listid=\"1\" aria-setsize=\"-1\" data-aria-posinset=\"1\" data-aria-level=\"1\"><span data-contrast=\"auto\">Migration-based (code-first or database-first)<\/span><span data-ccp-props=\"{&quot;134233279&quot;:true,&quot;201341983&quot;:0,&quot;335559739&quot;:160,&quot;335559740&quot;:257}\">\u00a0<\/span><\/li>\n<li data-leveltext=\"\uf0b7\" data-font=\"Symbol\" data-listid=\"1\" aria-setsize=\"-1\" data-aria-posinset=\"2\" data-aria-level=\"1\"><span data-contrast=\"auto\">State-based<\/span><span data-ccp-props=\"{&quot;134233279&quot;:true,&quot;201341983&quot;:0,&quot;335559739&quot;:160,&quot;335559740&quot;:257}\">\u00a0<\/span><\/li>\n<\/ul>\n<p><span data-contrast=\"auto\">The differences between the two are well explained in these two videos:<\/span><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335559739&quot;:160,&quot;335559740&quot;:257}\">\u00a0<\/span><\/p>\n<ul>\n<li><a href=\"https:\/\/www.youtube.com\/watch?v=j7OnxOz7YDY\">Getting Started with DevOps for Azure SQL<\/a><\/li>\n<li><a href=\"https:\/\/www.youtube.com\/watch?v=G7H6HbzwAfs\">Using Azure Pipelines for Azure SQL Deployments<\/a><\/li>\n<\/ul>\n<p>I really recommend watching them as they are full of interesting learnings.<\/p>\n<h2>I&#8217;m a newbie, this is way too complex!<\/h2>\n<p>I totally understand. REST API, JSON, Database, DevOps, CI\/CD, Pipelines, C# or Python&#8230;there&#8217;s a lot to learn. For this reason, I have also created a repository focused\u00a0<em>only<\/em>\u00a0on the data aspect so that you can start easy understanding that part:<\/p>\n<p><a href=\"https:\/\/github.com\/Azure-Samples\/azure-sql-db-ci-cd\">https:\/\/github.com\/Azure-Samples\/azure-sql-db-ci-cd<\/a><\/p>\n<h2>Master your data<\/h2>\n<p>As you may have realized, even if you are a back-end or full-stack developer, data\u00a0<em>is<\/em> important and thus dealing with it appropriately is definitely a must. If you liked this article and the video, I&#8217;m sure you&#8217;ll love this book I (co-)wrote exactly on the development and data subject:<\/p>\n<p><a href=\"https:\/\/www.amazon.com\/gp\/product\/1484263693\"><img decoding=\"async\" class=\"aligncenter size-full wp-image-420\" src=\"https:\/\/devblogs.microsoft.com\/azure-sql\/wp-content\/uploads\/sites\/56\/2020\/09\/practical-azure-sql-database-for-modern-developers-small.jpg\" alt=\"Image practical azure sql database for modern developers small\" width=\"153\" height=\"218\" \/><\/a><\/p>\n<p>Enjoy!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Video and sample code to create a end-to-end REST solution with Azure SQL, from zero to the CI\/CD pipeline, with Unit Testing too!<\/p>\n","protected":false},"author":24720,"featured_media":799,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[444,1,92],"tags":[409,448,93,410,486,485],"class_list":["post-796","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-net","category-azure-sql","category-devops","tag-api","tag-ci-cd","tag-devops","tag-rest","tag-sql","tag-unit-testing"],"acf":[],"blog_post_summary":"<p>Video and sample code to create a end-to-end REST solution with Azure SQL, from zero to the CI\/CD pipeline, with Unit Testing too!<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/azure-sql\/wp-json\/wp\/v2\/posts\/796","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/azure-sql\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/azure-sql\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/azure-sql\/wp-json\/wp\/v2\/users\/24720"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/azure-sql\/wp-json\/wp\/v2\/comments?post=796"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/azure-sql\/wp-json\/wp\/v2\/posts\/796\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/azure-sql\/wp-json\/wp\/v2\/media\/799"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/azure-sql\/wp-json\/wp\/v2\/media?parent=796"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/azure-sql\/wp-json\/wp\/v2\/categories?post=796"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/azure-sql\/wp-json\/wp\/v2\/tags?post=796"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}