Asp.Net Core 5 Rest API Step by Step

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments

You mean .NET 5?

👍︎︎ 5 👤︎︎ u/StanlyLife 📅︎︎ Jan 19 2021 🗫︎ replies
Captions
hello friends thank you for watching this video i am muhammad and i will be showing you today how to create an asp.net core 5.0 rest api we'll be creating a simple to do application where we'll be able to add edit delete and view to do items and we'll be utilizing sql lite to store our data the four things that we will need before we start is an ide which is going to be visual studio code the dot net core sdk postman as an application to test our api as well as a dv browser which is going to be called db beaver so the first thing is we're going to be downloading is the network sdk in order for us to get the network sdk we need to go to dotnet.microsoft.com forward slash download as we can see here we have two versions we have the net 5.0 and we have the net 3.1 we're going to be using the 5.0 as it's the one which is recommended and the latest one once we downloaded the installation is going to be straightforward it's going to be next next and after that the sdk should be installed successfully after we download our sdk we need to download our ide our id is going to be visual studio code we can get it from code.visualstudio.com it's also very simple installation and lastly we're going to need db beaver as our universal database tool it's a free tool that we can use you can download it from db beaver dot io for the slash download all of these links will be available in the description down below so once we install and download all of our requirements what we need to do is we need to test that our net sdk is installed successfully in order for us to do that we need to open terminal and we need to type within terminal.net dash dash version we should see the version number of our sdk in our case we can see that the version number is 5.0.102 which is the latest one if you're watching this in the future you could see different version numbers which could be higher or if you have another version of the net sdk installed you could see a lower number as long as you're seeing a number it means that the net sdk has been installed successfully if you see any other message you need to do is you need to redownload the sdk and reinstall it again once we do that we need to download and install our entity framework tool so in order for us to do that we need to go to the net tool install dash dash global because we wanted it across the os and we type dotnet ef since i have already downloaded before and installed it it's gonna show me that it has already been installed but for you it might take up to like five to ten seconds to be downloaded and installed once that's done we need to create our application in order for us to do that we're going to utilize the new keywords and we're going to create a web api we're going to give it a name we're going to call it to do up great we're just gonna click on enter and right now the sdk will create the application for us once we have this ready let's open the application in our sdk and our ide sorry now we can see our application has opened successfully in our ide so the first thing that we need to do is we need to see the terminal from within our ide how do we do that we just go to view and we select terminal and right now we can see that the terminal has showed up here so the first thing that we're going to do is we're gonna navigate to our application okay great and now we're gonna try to build the application see if it will build successfully in order for us to do that we're gonna be using a dotnet build keyword and we'll wait for a few seconds and we can see the application has been succeeded with zero warning and zero errors which is great the next step is we need to add some packages to our application these packages will allow us to utilize the entity framework as well as sqlite so in order for us to add those packages to our applications we're gonna type dotnet add package and we're gonna be using the microsoft dot entity framework core dot sql light this is the first package okay great it has been downloaded and now we're gonna install the second one which is gonna add package microsoft dot entity framework core dot tools okay great once we do that i think i typed by mistake okay framework add a typo okay great now we have the two packages installed successfully so once we have that let's try to run the application right now and see what do we have so dot nut run it needs access okay great okay after that we can see that the application is running successfully on port 5000 for http and port 5001 for https so let's try to open these up links and see what do we get remember we haven't added anything we're just utilizing the default source code for now so once we go we can see that we have nothing which is the expected behavior but let's try to open one of the controls that is provided which is going to be the weather forecast controller so let's see if we go to forward slash weather forecast we should be able to see some data coming if i can type successfully okay great we can see that we have some data coming from our default controller which means that the application is running as it should be perfect once we do that now let's clean up our application by removing all of the unnecessary code that the sdk has added for us and after that we start by adding our own controllers and our own code so first of all we're gonna be deleting this controller we're not gonna use it second we're gonna be deleting this class weather forecast control class delete perfect once we have that deleted we need to create our own controller we're going to call it to do contour controller so it's going to be new c-sharp class we'll call it to-do controller perfect once this class has been created in order for us to utilize it as a controller we need to inherit from controller base class well we can actually inherit directly from the controller class but when we had it from the controller class everything related to mvc from views management to cookies and all of that will be inherited to this class and since we're not going to be utilizing mvc we're utilizing so we're not going to be utilizing nvc we're going to be utilizing an api rest api we're not really we don't really need all of that so for this case we're going to be utilizing the controller base which is a much more smaller version than the controller class once we created uh we inherited from this controller class what we're going to do is we need to identify some attribute for this controller class the first one is going to be api controller which is going to be telling that asp.net that this controller is going to be an api it's it's an attribute that the sdk will utilize the second one is we're going to be defining a route for our controller so basically route is what's the path in the that the application or the clients that are going to be using in order to communicate with an application so in this case there is always going to be a frame a template that we're going to be following so the default template is going to be api forward slash and we're going to be utilizing the controller keyword within the two bracelet brackets so what does this what does this do so the controller brackets here as you can see one here and one here and we have the word controller inside it's gonna automatically inherit the naming of this controller so in order for an actual reading time the path for this controller it's going to be forward slash it's going to be api for the slash to do since this keyword right here it's going to be replaced by the word to do so this is like a built-in feature within uh the net core which is going to be replacing the to do controller with the word to do or any name that we give here basically so once we have this done let's create a simple action and we can see if it's actually running or not so in order for us to do that let's create an http get action and we'll have it as a public i action results and we'll call it test run so we can see if it's actually running and we're going to just gonna return a simple 200 with an success message message perfect so let's build the application again and we have to wait a few seconds okay build succeeded great now let's run the application perfect application is running now let's go back to the browser and instead of weather forecast is going to be as we mentioned earlier api forward slash to do perfect we can see that we have success has returned from the action and if we're checking it on our api testing application which is postman we'll be able to see the 200. now let's test this with postman so in order for us to utilize postman we just need to click on the plus button here and we said that our action is gonna be and get action let's copy the url and let's paste it here and as simple as clicking on send it's going to send the request to our api and we need to click on this one let's and perfect we can see that our api is returning at 200 status and with a success measured message which is great now let's go back to our ide and stop our application once we have this up and running and we have tested it and make sure that everything is working as it should be now we need to do is we need to add our model so within our application root directory we need to add a new folder and this new folder we're going to call it models and inside this folder we're going to create a new class this new class we're going to call it item data and within this class which is going to be our model we're going to define four properties the first one is going to be an id of type and the second one it's gonna be a string it's the name of our the title of our to-do the third one is also gonna be a string which is gonna be a description of our to-do item lastly it's going to be a boolean which is going to be defining if the item has been done or not okay great so now we have defined our model after that we need to build our api db context so in order for us to do that as again in our load directory we create a new folder we're going to call this folder data inside this data folder we're going to create a new class we're going to call it api db context perfect once the class has been created we need to inherit from that dbcontext class this class is provided for us by the entity framework package that we have installed earlier and after that what we need to do is we need to add our models to this apidb context so in order for us to do that we're going to type public virtual dbsat and we're going to be calling our item data and we're going to be calling this table items and we're going to put the getter and setters now let's fix the references perfect the next step for us is we need to initiate this apidb context so in order for us to do that we'll define the constructor and then we'll give it the db context option and we'll call it api in db context okay great and we'll put it options and since this class is inheriting from the dbcontext class what we need to do is we need to send this variable to the base class so base and we'll send the options directly there perfect so now let's just build it make sure that everything is running as it should be and we don't have any typos and we have to wait for a few seconds and we got that bill succeeded with zero warning and zero errors perfect so let's do the small summary of what we did so far so the first thing that we did is we created the application using the new keyword second is we cleaned it up from all of the built-in code that dotnet sdk provided us then we created a test controller we called it to do controller and we created a test action called the test run we're going to be removing that later on after that we created our model it's going to be a very simple class it's called item data which contain the id title description and a boolean if this item is done or not and lastly we created our apidb context and we then initialized the item data inside our db context which is great so once we did that our next step is to add the connection string to our app settings and then inject our db contacts into our startup class in order for the application to know what type of database is going to be using and what how it's going to be utilizing it so the next step for us is it's going to be as simple as going to the app settings and within the app settings we need to add the connection string and we're going to be calling it default connection and we're gonna since we're gonna be utilizing sqlite we're just gonna be using data source equal app.db and we're gonna put the cache equal shared so just to summarize this connection string here is gonna be responsible to create and sqlite database inside our root folder so once we have that now we need to update our startup class in order for us to utilize that connection string so within our configure services before the services.addcontroller we're gonna be adding services dot add to b context which is basically gonna be calling the database middleware we're gonna pass our api db context let's fix the references and then we're going to be defining the options and we're going to within those options we're gonna be telling and asp.net that please we're gonna be using sql lite and within those we're gonna be defining our connection string using our configuration services and we have called the default connection okay great so now let's fix our references okay perfect we have every issue resolved when it comes to the references let's build the application make sure that everything is still building as it should be perfect good so once we did that now we're ready to add our first migration so just to give a quick summary on this this phrase here or this sentence here what does it do so within our configure services we are injecting the server the middle words that asp.net they're going to be using in order to initialize the application so within the services we have adddb contacts which is going to be connecting to adb middleware we're passing at our own database configuration which we have defined here it's going to be a simple db contest containing a single table called items and then we have defined the options for this middleware telling it that we're going to be utilizing sqlite with basically what type of database we're going to be connecting to and then we're giving the path of where this database exists from the connection strings uh configuration that we have added inside the app settings very simple and very straightforward so once we have those it's time for us to add the migration so how do we gonna add the migration first of all let's look within our application structure we can see that we have we don't have anything called migration we're gonna be utilizing entity framework core in order for us to have this migrations created for us so in order for us to utilize it we're going to type not ef migrations add and we'll call it initial migrations because this is going to be the first migration that we're gonna create once we type press on enter it's gonna take roughly around 10 to 15 seconds they're gonna build the application and then we can see it has been done successfully and we noticed on our left hand side we have a new folder called migration so what's inside of it so if we open it we can see that we have some c sharp code which is automatically generated for us by entity framework we can see that it's this t sharp code is going to be responsible to create a table named items and within this table we have four properties which is going to be id title description undone and every one of them has the different types which is the right way and which is the right information based on what we have defined inside the item data model great so right now we have our migration scripts ready how do we actually put this migration into a database we're going to also be utilizing entity framework again to do that and the keywords for it is going to be not database sorry.net ef database update these commands here they're going to be taking all of the migrations that we have and they're going to be implementing it so since within our connection string we have defined the app.db the affiliate entity framework will check do we have an app.db already created if not it's going to create it for us if yes it's going to be using it so in our case we don't have it so we can see on our on the left hand side that entity framework has created the database for us and it has applied all of the migration to it which is great so the next step after we do that is we need to check this database and make sure that it's empty so now we need to check our database using our db browser so once we open db beaver let's add a connection to our database we're going to be using sqlite next let's browse where does application exists youtube to do it's called app.db press on ok and now let's test the connection first it's gonna require a driver okay perfect and now let's click on finish and we can see our app this db here is created and we can see there's a single table called items and if you open it we can see there is no data inside of it which is what we want right now great so after we do that now let's try to build our infrastructure and now let's start utilizing our to-do controller that we have created earlier so let's go back to our controller and the first thing we're going to do is we're going to be removing this test action that we have created and we're going to be connecting our controller to our application db context so in order for us to do that we're going to be creating a new instance by first making it private read only api db context and since it's private i'm going to make it context let's fix the references then we need to define our constructor and then we're gonna inject an apidb context through our constructor and then we're gonna link them up together inside the constructor so this is a simple initialization of the application db context and as you can see it has already been initialized here using the constructor and the way it has been initialized is by using dependencies injection and the way that asp.net core knows how to handle this dependency instruction it's gonna look into our startup class and it's gonna see the service that we have added once we have added the service that nut will know that okay we need to inject this within the constructor and it's going to be handling all of the heavy lifting of doing the initialization for us so this is why we can directly utilize it here without any further configuration because dotnet is gonna be do doing all of the heavy lifting so the first action we're gonna be adding is gonna be cut all items so since we're gonna we're getting all of the items it needs to be i got so first we'll start with the attribute http got and then it's going to be public i action result we're going to return and we're going to call it get items and then basically we're just gonna be connecting to our database pulling all of the items that we have and returning them so we're gonna be var items this is the variable that's gonna be saving all of the items that we got back from the database we're gonna be using the tv context we're gonna be using the items table and we're gonna put use the tool list async okay so let's fix the references and since we're going to be using async here let's we need to avoid this and since we're going to be using await we need to make this one an async function so since we're going to be reading data from somewhere outside the system it's always better to utilize async so we don't hold the main thread of the application while it's running so once we have got all of the items back we need to send it back to the user or to the client by using the ok keyword so it's going to be return ok items so putting the i came items within an okay means that we're returning a success a status code with of 200 as well as we're returning it in adjacent format so let's test this out bear in mind that currently our database is empty so we don't have any data to return back to the user so we should see at least a 200 status code so let's put dot not run okay perfect application is running let's go back to postman and within postman just let us call get the main one and we put on send and we can see we have an empty array it's going to be turned back because our object is empty and because we don't have any data inside of it and we can see we have a 200 success which is the right outcome that we were expecting great after that let us start by adding more stuff into our items so how do we do that so since we are getting stuff or we are giving actions to our api we need to make it within an http post when whenever we need to add stuff or add stuff to our database it's going to be a post or basically there's any actions i know this is a very oversimplified terms in order for us to do it but if you're a beginner you need to think about it this way anything any information that you want to get from the api you'll put it in a gut and any actions you want to execute against an api like saving information editing everything where it's going to be a patch or a put but for example adding information or executing some kind of action you need to send some data to the api to process it it's going to be a post so first we'll define it as http post and then we'll define it as public async and since we're going to be communicating with the database it's always have to be it's better to be async so we'll put it within a task and we'll call it create item and for us to process it we're gonna be sending it and json which has the format of item data and we're gonna call it data okay let's fix the references perfect and now how are we going to handle this so first of all we need to make sure that our model which we are receiving from the api is valid so we type f model state dot is valid so we're utilizing some of the functionality that asp.net provide us which is a model state validation if it is valid we're going to be processing it if not we're going to be sending the user a 500 error or any message that we like so we can put return new json result and we're gonna put a message for example something went wrong and we're gonna give it a status code for example of 500. okay perfect so now what happened if the application the model state is actually valid we need to add it to the database in order for us to do that we just use await because it's going to be communicating with the database we'll call the dbcontext items add async and we'll pass in the data and then we need to save those changes to the database so when we do context items that add async it will add it to the memory within the application it will not save it directly to our database it will only add it to our memory within the memory of the server itself if you want to actually write those changes to our database we type await contacts dot save changes the save changes keyword basically is going to take all of those changes that we have done with and it are saved within our memory it's going to generate the sequel for them and then it's going to execute them against our database perfect so now we have created this uh we have saved the information so what do we need to return back to the user in order to let them know that the application our the job of adding this item has been processed successfully we need to follow the rest api standards so the rest api standards tells us that once we create an item we need to return that object back with a status code of 201 and does not make it easy for us to do that by utilizing the created action method so we're going to put return created at action we don't have the get item back so we created this after this one so basically it will allow us to return one single item at a time and then we're gonna be returning the id which is gonna be anonymous object we call it data.id and then we're gonna return the actual data object which has been created so before we run it let's create this get item and then we run it and test it out so the get item as we can tell from the name of it it's gonna be returning a single item here we are getting all of the items so in order for us to utilize that since we're getting information has to be http gut and since basically we're getting one item we need a way to identify which item we want to get and since within our model we can see that we have an id we're going to be utilizing the id so in order for us to utilize it we can just add it here within our http gut and that way once we send to our api the same request i get with an id it knows that it's going to come to this action itself to get the single item that we want so once we have that now let's create the action by itself so public async task i action result and then it's gonna be cut item and we're gonna pass it the id great once we have that now let's just connect simply to our application db context and let's get the item so we'll put var item equal since we're communicating with the db it's always to have it as an async method so we'll use the await keyword context dot items dot first or default we're going to be utilizing some entity framework keywords and then we're gonna pass the condition which is gonna be matching by the id okay great now once we have that we need to double check that the item is not empty so in order for us to do that we'll put f item equal equal null we're gonna return are not found the the id is not valid we'll put return if i can type not found perfect and then what we're gonna in case the item actually exists we're gonna return it but then okay with the status of 200 which is going to be item okay great let's try to build the application see if everything builds successfully application builds now let's run it it's running great great now let's open postman again and let's try first by posting something our ending a new item so post and let's take a look at the action by itself so it's going to be a post recommended as a post done is have gonna be the same url right and now it needs an item data object as a json so how do we do that so within postman we need to click on body and then we need to click on row and then from this drop down menu we need to put json and then we need to define our json body here so within our item data we have title description done and id so when we want to send this object to the api for the process since we are utilizing entity framework or and we have already defined it as an object and once we do that entity framework will know that id since we gave the the word id here entity framework will make this as an automatically generated primary key so if we look here at the migration script that has been generated for us we can see that the id is has been an integer and has is not nullable so it cannot be null and entity framework automatically gave it an auto increment a location annotation so that means that whenever we create add a new record the database will automatically update the id we don't have to worry about that and we can see that within the constraint our database entity framework has automatically make it as a primary key so for this reason when we want to send the object to the api at this moment in time to create a new item we don't really need to send an id so all we need to do is send and title description and the boolean so first we're gonna send the title let's call this one our first item then we're gonna add a description and we'll call this description okay we'll call this this is a nice description for the first item and then the last one gonna be is it done we're gonna say no it's not done so we're gonna put it as false okay great so we can see that we have title description undone and we make it as post now now let's make sure the application is running yes it's running and now let's send it okay great we can see that the application has returned for us i201 status code which means that the adding has been done successfully we can see that an id has automatically been we can see that from the response an id has automatically been generated for us one and then we can see we have our title description undone perfect now let's switch back to our get and let's now get all of the items that we currently have first let's add a couple of more before we do that so let's call this our second item and let's make it second and we'll put next to it number two and ascend it and now let's add a third that we will have some data to play with third third and last add one for example uh read a book let's make it uh the about higgs boson for example and for example as another one play xbox and description play the new halo games for example send okay great so now we have a couple of items that we have added now let's test it out let's go to get and let's put body as none because we don't want to send the body with this and click on send and now we can see that the api has returned it for us all of our items that we have added play xbox reader book our third item second item and first item perfect so now let's try to get one single item so if we follow back the actions that we have in our to-do controller and we can say we can see that in order for us to get one single item we need to pass an id so let's pass an id of for example three and let's click on send and you can see our api returned to us only one item which is gonna be our third item if i type three four instead of three and i send it we can see the api return the four read a book and learn about higgs boson perfect so in order for us to do just a quick summary we did uh i got all so basically get all of the information that we have get so we got a single instance and we did a post which is gonna be adding some information to our database the next step for us is to modify one of the uh modify the data that we have in our database so let's say we we one of our to-do lists for today was read and read a book and we actually read it and then we need to change the status of done from false to true so that way we are updating the object so within rest api you know if we want to update an object we have two methods so we have a patch and we have a put so what's the difference between them so basically if we're going to update the entire object if let's say for example an object is formed of for example 15 fields and we want to update all of these fields at the same time we'll use put so basically the put action is going to take everything within our json object that we send back to it and it's going to update every single item within that object that we have the second one is patch so in our case for example we have only uh one item for we want to update let's say we're gonna update the property from done from false to true so in order for us not to send a big object to the database to the api we're gonna only gonna send one object which is gonna be done so for this one it's gonna be simple and quicker we'll use patch but for our demo example right now we're gonna be illustrating the put example because we're gonna be updating the description done under for example the title if you want so how do we do that let's switch back to our visual studio code and let's add a new action so since we said we're gonna be editing the information this action it's gonna be a put so we'll put http put and we're gonna give it an id as well as an object y so in order for us to utilize and to make sure that the information we are sending is consistent on top of the object that we are sending we need to send the id with it so we'll send the id and we'll send the object and within that object itself we can add the id so we have to match them together and make sure that this object that we're sending is valid so we'll put an id here and then we'll put public async task i action result we'll call it update item and we're going to give it an integer it's going to be an id as well as the item data which is going to be the object that's going to be updating i'm going to call it item so the first thing is we need to make sure that the id that we're sending actually match the id within the our item data so for us to do that we're gonna be f id equal sorry not equal to item dot id we're gonna return a bad request so we are just following the http uh sorry the rest standard in order for us to do that so the second thing is once we knew that both ids are equal we need to get and check if this item actually exists within our database so in order for us to do that we'll get create a new variable we'll call it exist item equal away since we're communicating with the database contacts.items dot first or default async and we're gonna be matching it on the id okay great so if exist item is equal the null we're gonna be returning are not found sorry for that okay we're gonna be returning are not found the second step is after we check that actually we have an item with that id we need to update it so how do we do that we can put exist item dot title for example we'll name it item.title exist item dot details descriptions are equal item the description and lastly exist item dot done equal item dot done so we're basically taking all of the values that comes from the item data and we're saving it inside the exist item there is a way better way in order for us to do this instead of doing it manually one by one by using automapper but that that's a topic for a different video for now since that's very small object we're just going to be doing it manually one by one once we have saved them uh we just need to update our database contacts because as we have mentioned earlier once we're doing any updates all of these are currently being done in the memory within the server in order for us to write these changes to our database we need to type await underscore context and then save changes async these this keyword here will actually add a comment here implement the changes on the database level perfect so again in order for us to follow the standard for rest once we are doing any update on our database we need to send no content as a response so put return no content and this no content it's gonna have a http uh code of i think 204 which mean has been done successfully and there is no content to be returned back to the user okay great now let's test this so let's go back to postman and now let's change this from get to put let's go back to body it's going to be raw and we're going to be updating the first one here we have to add an id because the object expecting an id to match the one we're sending in the url and instead of for example being item one we're gonna say do shopping and within the description we're gonna make it do weekly shopping so before we do that let's see let's copy this and let's see what was actually in the first one and see how it changed so let's paste it here and let's do send and we can see basically we just opened two different tabs so we can compare the results so before we did this the first item in our to-do list was the title was our first item and a description this is a nice description for our first item we want to update that to actually to be something meaningful like doing shopping so let's run this and see what happens so just to summarize we made it a spot we added one to our query string and then we defined our object with the id1 title description undone now let's send this okay that's we got a 405 not allowed i'm not sure why we'll debug it and see what's the issue and then we can see that nothing has happened if we run this nothing has happened let's see what went wrong so let's stop this and so id not equal to item.id equal but request correct exist equal context items first or default correct okay that's good just updating it and return no content okay that should be fine uh let's try to build it sometimes i forgot to build and rebuild maybe i haven't rebuild it no last but not run okay let's go back to postman so we have an id check of one title description undone let's try it again perfect maybe i haven't rebuild it and we can see we have a 204 no content which was the expected one and now let's try to send it again and see if we're receiving the updated version perfect now the one has been updated from do shopping from item 1 to do shopping and do weekly shopping now let's update this one to be true again let's test it out we're just going to change this value from false true let's send it it says has to offer no content and now let's check here perfect we can see it has been updated great so we have done four out of the five basic rest api request now let's do the last one which is gonna be deleting an item from our list so how do we do that again it's very simple as you might have expected we need to do the http delete attribute and since we're gonna be only sending an id because we don't need anything else we're gonna be adding the id first let's stop the application okay now let's add our action so public async task i action result delete item and we're gonna just take an id of end type end and then first of all we're just gonna check if this item already exists so far exist item equal await context.items dot first or default and we're to be matching it based on the id equal equal id perfect and now if exist item equal equal the null we're gonna return not found because the id is not doesn't exist else we're just gonna using the context dot remove sorry dot items dot remove and we're gonna pass it the object that we found so this will remove it from the memory as we agreed and now we need to save it into our database dot save changes async and lastly based on our rest api standard we need to return the object that we have deleted and in order for us to do that we'll return it okay exist item and perfect let's try to build this it should build successfully great and now let's run it okay perfect it's running now let's go back to postman and let's try to add for example one more to do item we'll call it let's see play sports and description for example go running go do a 5k run for example and this is false now let's send this now we should see it returned for oh sorry we needed to update these so this needs to be opposed okay now let's send it again perfect it's added successfully now let's try let's check this out it should show here that we have added we have six item okay great now let's try to delete the second item because it doesn't really make sense to have it on our list so let's go to post let's go to delete and let's give it id2 and let's remove the body from the request and let's send it and we can see that the application has returned a 200 and it returned for us the object that has been deleted now if we get all of the object targeting system within our database we can see that it jumped from one to two three because two got deleted successfully which is the outcome that we are waiting for okay great so this is basically some uh complete our basic rest api this is gonna be a part one of a series we're gonna be building this api and adding more functionality to it so what you can expect from feature video is adding authentication adding authorization and for example gwt tokens how we can authenticate against our database using a username and a password maybe creating a front-end for it connecting into a mobile app for example publishing it into azure using docker containers we're just going to be building bit by bit this application so it will be a fully fledged to do application so one last thing that i wanted to mention within the net 5.0 release as we can see let's go back to our application and go to our startup class we can see that the auto-generated code for us has added a swagger integration great so what is swagger swagger is a tool or a package that is installed within our application that will describe the structure of the api for us and it will make it easier for us to see what our controllers are what our actions are what type of input do they take what type of value do they return and all of this configuration and all of this is done for us in internet 5.0 out of the box so we don't need to do anything else as we can see as soon as we created the application this is swagger integration and this package has been automatically installed and has been added for us which is really amazing if you think about it because prior to that and i think all of the dot net prior to that all of this work has to be done manually so we had to install the swagger packet then we have to configure it and add all of the right configuration so how do we actually utilize swagger and how we can see it so if we go the application is still running and now let's go back to our browser let's open the browser let's open the browser sorry i think i'm losing my voice okay great so within our localhost instead of going directly to the api what we can do is we can just type swagger forward slash index dot html and we can see that swagger has automatically populated for we didn't do any of this work we didn't do any of the front end for it we didn't do anything if this was provided for us out of the box from the net f 5.0 so we can see that we have our get post get single item we have the put and we have the delete and as well if we click on item data it will show us the object that we need to create that we need to send do any of those actions and all of this we got without doing any extra work all thanks to the net 5.0 sdk which is great i just wanted to mention this at the end because this has removed a lot of work from the developer who wanted to add them in a previous version of that nut so just to summarize what we did today is we created an uh web api application using the dot nothing new keyword after that we cleaned up the code then we created a sample a controller called to do and then we added a test action we tested it out and then we added our application db contacts and we added our models after we added those we just configured it within our startup class and then we added our application settings which is going to be an app settings sqlite database and after that we just added all of the actions within our controller to manage the data which is going to be adding deleting viewing listing uh all of our data for example and managing it thank you for watching this video please like and subscribe and share if you find it interesting
Info
Channel: Mohamad Lawand
Views: 9,865
Rating: undefined out of 5
Keywords: aspnetcore, rest, webapi, efcore, code first, beginners, step by step, tutorials, sqlite, swagger, postman, net5, dotnet5, dotnet core 5
Id: p_wUdWshYc8
Channel Id: undefined
Length: 57min 41sec (3461 seconds)
Published: Tue Jan 19 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.