Create new Web API project in .Net core 7

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
okay hi everyone so in this session we are going to learn how to create net core AP API project by using the net 6 and visual studio uh 2022 okay so I'm just going to open the visual studio ID okay so here if you go to the create new project okay so same uh we can create the console application from this window you can just search for console app it will provide these templates you can choose the template click on next next finish you can just create the console application now this time I just wanted to create the a project so for that you can use net core web application model view controller okay I wanted to create the wave apis in model view controller format so you just have to select asp.net core wave app model view controller okay if it is not available here because it is in my recent project template you can just find the same template here okay find it net core web app you will find the template choose that click on the next button okay now just provide the path so I wanted to create the net core application on this path and API project name should be that's a library library web apis Okay click on the next okay okay here you can choose the framework whether it is six or whether it is seven okay and click on the create button it can be 3.1 also if you have installed that it will available here and you can just choose it okay now uh if you see here in the visual studio here we are having a solution Explorer okay so this is the main window where you can see what is the folder structure of your application what are our files available in which file you want to create uh write the source code or program all these things you can just just choose from here okay it is very important window okay if anyone ask you to open the solution Explorer make sure to go to this window only okay so this is the default folder structure created by uh template project here you can see controllers models and Views there are three different folders available what is controller controllers are nothing but uh it will help you to handle request and response of your application okay in the controller you will have the api's endpoint okay from the web API it will give a call to the models it will give a call to the Views oh is it MVC application I have created sorry let me just close it I want to create weave API project not MVC give me a minute yeah choose this template net core wave API not wave app Okay click on next let me delete the old one okay now if you see the solution Explorer you will have the controllers only no models and no views okay so this is right application now so in controller we will have the actual end points so endpoint means the web API okay so inside this this can be web service the whole project is a web service service inside this web service we can have the web apis and for writing the web apis we will require the controllers okay so this is actual entry point to your endpoint you will have one app setting. Json file this is configuration file inside the app setting. Json file we can add the configurable variable meaning so if you want to change some values some secret keys after deploying your application or as per your environment that you can make it configureable inside the app setting. Json file for example uh you are having one you are having one database connection string okay currently you are connecting to your local database and if you want to host your application you want to connect with the production database so that connection string you can just put into this file so that way you can change it anytime okay any value you want to change it later that can be your confiable value and that confiable value you can keep into the abing notation next one is program.cs okay so program. CS is nothing but your entry point method entry point class okay so it will basically help you to enter into your application okay once you enter into your application these are the things your application can do okay it will add the dependency for controllers it will add the Swagger gen tool it will add builder. build okay it will help you to run the Swagger y Okay add the authorization https redirection map controllers run controller so all these things are required as a base application okay now I wanted to create some apis so in order to create the apis we need to let's say create One controller okay okay let's say I wanted to create One controller like book controller okay but is book why book controller because this application is library right we apps so for Library we can have entities like book author okay or too many others so let's create book controller it will help you to create the book get get all books Save Book then get book by ID get book by authors okay delete book update book so these many API we can just create here inside the Library there is the book controller inside the book controller we can create the web page okay now let's say uh in order to create the book API I need to first of all rename the Constructor as well as well as class name okay this I don't want when you will create a new application by default you will get this controller weather forecast we don't require that just delet it okay I just want my own controller where I will have some wave a okay so here also I require to add book controller name book controller name and this is the W so let's create one endpoint if I call gate books it should return me list of books okay so this is how this this is the Endo I wanted to create so you can see HTTP get annotation is there get means we can use the HTTP gate when you want to retrive something from the server you want to get something from the server okay and you don't want to pass any payload or large payload to the server in that case you can use HTTP gate okay so my endpoint name name is get all books okay so this is the endpoint name now I wanted to retri the books but for returning the books I should I should have some book model or something okay but that we will create later now I just wanted to write the simple API which will return me the list of books in the form of string okay so book one comma book 2 comma book 3 like this I just wanted to return to the server to the UI or client you can just create one array like list of [Music] string books is equal to new list of string okay and here for time being I'm just going to add some book names like book one comma book two comma book three okay so I have one list of books I just wanted to return that so I will do return books that's it okay so this is how we can just create our first web API by using the net core application what I did I have just created one web API project inside that I have created one book controller inside the book controller I have just rename name uh the Constructor this dependency for ilogger and then I have just created one Endo that is get all books and that we can just write here okay if I rename the action method with some custom name in that case you will have to add uh square bracket action in the route attribute why we require to add that because this is is no longer rest rest API now okay this is like rest API has the ability to identify end points by their annotations like HTTP Gate Post put patch delete but I wanted to give some custom name to my methods no gate no post it is gate all books Save Book okay gate book by ID like that if you want to provide the custom name to your endpoints then you can just mention forward slash action here okay so run this project you will get one endpoint that is get all books and then if you call that endpoint it will return the list of books okay let's see how to run that project just click on the https button here okay so if you run this project it will open the Swagger U what is Swagger Swagger will provide you one UI which will help you to see what are all end points available in your project and by using the Swagger U you can just call those end points okay so let me share that screen as well you can see with that this one okay you can see uh I just run my project and here Library w AP Pro got created this is the version and this is the Json file this Json file is nothing but your open API specification okay so this open API specification will tell you what is the path of your API what is the parameters and what can be the response of your API so this is the open API specification if you want to see this specification in UI for format so this is the UI okay so this is the library web API where get all books API is now created the type of this API is get and if I run this API you can run this API by using the try it out button okay just click on this button click on execute you will see the output here this is your output book one book two book three okay so this is your first wave API in net core okay so let me check the syllabus yeah we got the introduction we have created a simple asp.net core web application and we got the understanding about the project structure and now we have created one sample API also okay let me stop the recording
Info
Channel: Code With Bapu
Views: 581
Rating: undefined out of 5
Keywords: programming, c programming language, c# (programming language), c programming, what is c sharp programming language, programming project ideas, c# programming, c language, c programming projects, c sharp, java programming language, c sharp tutorial, top programming language 2022, best programming language, how to learn programming, programming project, introduction to c# programming language, how to learn c# programming language, uses of c# programming language
Id: SBUkNaPTaEY
Channel Id: undefined
Length: 13min 52sec (832 seconds)
Published: Wed Nov 29 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.