.NET EFCore | Publish your Web API and SQL database to Azure Service using Visual Studio ONLY

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello everyone welcome back again to  netcode Hub channel in this lesson we are   going to facilitate on how to deploy your  asp.net core web API to Azure app service   with the issue of the visual studio so  we are doing everything in the visual   studio that's awesome you know when you create  your API and you want to have publicly access   you have to put it online for people to have  access to so you want to now move from local   from a computer to the web and you know Azure  Alpha has a free service that we can actually   publish our web API to it including the Azure  database as well so in this lesson we're going   to have a look on that so we first have to create  a web API so here I assume you know how to create   your web apis you have to create your services and  your controllers and everything so for example is   what I've run on the screen like you see we have  this simple controller here for a separate project   now with this API this I want to do I want to  just Host this online so if you check the URL   here it is from the localhost meaning aside from  this my machine no one can have access to this   but we want to put it globally so that everyone  can even have access even EU we can have access   to this API in such case how are you going to  do it that is also going to have a look today   so let's see now first of all what you have to do  here is we have to go to this that's a project now   this project we see from me I have my database  connection here and in this we let's stop this   so we have to go to our project now right click  on the solution and I can go to publish and   that's going to be the project title and I click  on publish so you make sure you are connected to   internet as well now because you're going to have  this as a pop-up now as you can see from the title   it is published so what you want to publish to  we select this Azure and I will click on nest   now you see we have a lot here so it is asking us  to specific Target that you want to use and I said   you know I'm using Windows I'm going to choose  on this windows and click on Nest to move on so from here you have to sign into your Microsoft  account so if you're not having one it means you   have to create an account in that Outlook or  Hotmail you can create one now when you come   here you can see we have this subscription and  that's the Azure subscription one so this is an   auto automatic one so okay we have subscription  name and that is the the name selected over here   and the next thing to do here is we are going to  create a service so you can see here we are not   having any instance so for this we have to click  on this create new to create a new instance of   the service so here you see we have this pop-up  and now it has given us a name that you want to   use so this patch ambulance you see there's  an automatically selected and when you come   to the next step you can see we have a resource  Group and a hosting plan we have to first create   a resource Group Resource Group actually organizes  all your resources in one group and give it a name   so let's see let's click on the new Resource  Group and and there is a resource Group here   so we can still add this and let's say this is a  dispatch ambulance API we have the number right   there the resource Group is okay and now when  it comes to the hosting plans you we want to   get a free one so we have this plan and as you can  see from this location you can choose a location   over here and aside from choosing  this location so let's the default one   then here we want to use the free version so  click on the free version and then click on OK   so you have a resource Group created and that's  a resource Group here we have a hosting plan also   selected and now the next thing to do here  is to click on create so you can see it's   going to revalidate everything and I wait for this  Resource Group and on this session to get created so after successfully created you can see  you're going to have this page and now the   app that you created a service that you  created has been automatically selected   you can decide to create new one or  use the same one that we've created   so we're going to click on that as you  see and we're going to click on nest   so yeah we're gonna talk about API management  but for now we're not going to talk about EP   management now maybe you can talk about this later  on and how to integrate API Management in your API   service that you are creating or uploading so  let's skip this for now and now click on finish   so we wait as you can see from here it is creating  a profile for us so let's wait for our profile   to get created so you can see that it is now  created successfully as you can see from here   so let's click on close now we are in so  let me just close this up so we are in here   so from this end you could see that it has  detected some dependencies and that is the   first one is we have the Azure API management  and the second one here you can see we have   SQL Server database so we have database that is  the back end of this and we have to connect this   to the API or the web service as well so let's  click on this and as you can see from here we   have connect to Let's click on disconnect and  actually we have this pop-up open so what I'm   going to choose you make sure you choose an Azure  SQL database so we select this and I click on nest   please so in here you see we have an  SQL database and we have to create a   new instance of this SQL database so we do  that by clicking on this create new instance   so as you are in here we have a new window and  this is a resource Group so as you can see from   here we have the same Resource Group created and  we have to use that we can decide to create a new   Resource Group as well but here you're going to  maintain this Resource Group diary created earlier   on and now editable it server we have to create  a server so let's click on new to have a server   selected now these are several names so as you can  see from here we have a dispatch ambulance dot API   DB server okay the location and I have to pass  in the administrator username and password as a   confirmed password so let's do that when you're  done with that click on okay to move on with it so when you're done then you click  on create as you can see from here   everything is intact so click on  create to get your account created that's right so it is not ready and now let's  select a database and I'll click on next okay so you can see we have our connection string  value and we have our database connection name   so you have to pass in our connection um  string name and as you can see from here   there is it's requiring our username and also  our password so for user name I think it is azure so Azure database username and now the password I just  have to pass in my password that I use   so after that then that's what  I'm going to do just click on   you have to now go there and choose a connection  string that is the default one like that and the   next thing to do is click on nest and as you  can see from here we have this project changes   for dependencies being added or configured so all  these have been added so the next thing to do is   you have to click on finish to get it finished  okay so it is connected now let's wait where   the connectivity is in process and let's  just as you can see it is inside these   packages on the database on a server for us  now when it is done then we can now move on okay so you see from here that is completed so  yeah it's configured so we can now click on close   so you can see from here database is now connected  but there's one problem you know when we check our   database we have some migration file that was  made already and now with this migrations we   want to include it here maybe this migration may  contain seedings and that's the default value that   I want to set to a database and Etc so in such  case what can we do we can now edit this and now   apply this migration which is going to take effect  and now all the data that we have in database is   going to also include into the current or the  new database that we have so in such case how   can we work on this you can do that by clicking  on this small action and now click on this edit so let's wait for it to finish  discovering data context so let's click on this drop down that  is the Entity framework migrations and   I click on this apply this migration  on publish and now let's click on Save   that's the only thing that we need to do now after  doing this what you have to do here is to click on   publish so now let's publish our app and it's  going to take um some few minutes for this to   be done as you can see from here it is second if  your application will run successfully so you are   publishing the application without bundling the  the runtime so let's switch while there's in all   this compatibility check-in and this publishing  aspects so we have to sit and I'll wait for that so you see that web app was published  successfully and I can see we have our   URL over here and installing ASP core site  extensions so we wait for this to finish   and automatically it's going to pop up a page  for us and that is where we have our API now   okay let's wait for this to get loaded and  I will see you know when we load the default   API from the local you can see I'm not seeing  this you're not seeing page 404 that is not found   now if you check this our API over here so  you can see from here if I click on run this   this is going to run and at the default page is  going to be the Swagger but here we are not seeing   any Swagger here we are not seeing Swagger here  we see all of this but with this and the API of   it if we decide to navigate to any URL here  it's going to have that also now let's see   so this is our Swagger you could see  as soon as the page load that API   load you have the interface here and  let's say uh when we go to get users   so let's get drivers and if I click on try  this out you could see it's going to execute   and now you're going to have the route and  maybe some content over here let's switch   so this is the driver that we have and here we  can actually go in there and now get this API   or this driver so let's let's try that here  and see so let's copy this and let's go back to   our page here so in the API we paste this  and go for drivers unless you're going to   have access to the driver that we have you know  we have only one record and let's see if we're   gonna have that record in here okay so we are  not having this record meaning that the record   that we're on database was not added to the  database but we can decide to post new data   here to do that we have to get access to the  Swagger so you can have access to this post   now let's see how to do that so let's  go to uh project and in our project we   go to solution Explorer and now  let's go for the program.ts file so inside this use Swagger under a  development use this Swagger UI let's   specify some parameters in it and now in here  we're going to say that we're going to have this   Swagger then maybe version one and  let's have this Swagger dot Json and in here we are going to specify the  name so I'm going to say this is dispatch API maybe V1 that's a version one  and also we let's terminate this and now in here so we're going to specify this  in the middle of this Swagger UI so we can   just have to cut this off let's cut this off and  inside here you can just use this configuration   then we're going to extend it like that Swagger  endpoint now with this end point we now specify   this in the end point also at the end we can  also specify C dot now routes prefix and I want   to send this to string dot empty so that as soon  as we run the application we run our page we will   have that the page full form write the error  code so let's save this now let's stop this   and now let's publish it again so click  come here and I'll click on publish or as you can see it is successfully published  and it is navigating us to the same page again   and now as you can see from here we have our  Swagger in our web API online so let's see   let's try to get all employees to try this  out now let's see if you're going to have   some employees in a database if not then  we create a new one so when you load the   page you're going to have this default one  so you can see there's nothing here let's   try to add driver here to this so try  this out and I'm going to execute this okay so successfully I did now when  we check for get drivers execute okay so you can see we have one driver here added  so that is the the the easiest way of deploying   your web API and the database into Azure app  service by using the visual studio I believe   um this video is okay thank you so much  for watching please give me thumbs up   or if you like what I'm doing also  check our playlist you have a lot   of projects and lessons for you concerning  blizzard.net my reapplication development   hopefully I'm going to catch  you up in the next video
Info
Channel: Netcode-Hub
Views: 647
Rating: undefined out of 5
Keywords: asp.net core, Registration, send email using mailkit, mime, controller, service, email service, web api, send email through web pi, smtp, SMTP, EFCore 7, skip(), take(), skip() and Take(), skip and take, local storage, blazored localstorage, window.localstorage, scalffold, scaffolding, db-first, migration, database migration, scaffolind db first migration, creating models, fileupload, blazor fileuploads, crud operation using SqlServer, CRUD Operation, app service, api
Id: -wtRY2IepGE
Channel Id: undefined
Length: 16min 46sec (1006 seconds)
Published: Mon Aug 21 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.