Swagger in ASP.Net Core Web API Tutorial -EP-17

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey guys welcome to my channel today we are going to see one more interesting component of dot net core web API which is Swagger Swagger we used to documenting the rest API Swagger open API language agnostic specification for describing the rest API it allow both computer and human to understand the capabilities of rest API without direct access to the source code in a main goal minimize the amount of work need to connected to decouple the service and reduce the amount of up to documentation timing okay it actually reduce the amount to create documents the manual documentation so let's go to our visual studio and see how we can apply so I'm using here Visual Studio 2022 I'm going to create a new project so here I am going to create a dotnet core web API project I'm giving here Swagger demo I will keep this application Google Drive and the and I will give the link on the video description so you can download this also click on next so here you can see there is a open API support if you are this one so automatically it will add everything ok but if there is any existing project how we can add this open API support so I don't need https so I'm keeping checkout for now this one and I'm going to use controller and I'm not going to use open API I'm going to use manual here now so let's create the application so this is our application but created downloading a new time let's hit the Run button and see how the operation is running so you can see directly going to this controller or this API and hitting our default template which is weather forecast service this is the model and this is the controller it is going to this and redriving but let's add one more controller here it's probably the operation from running let's add one more controller here so I'm giving one more controller here so web API controller are so here I am giving YouTube test controller so I have added one more roller YouTube test controller and one more get string here just like the weather forecast right this is the gate so let's run the application and see the difference she's slightly going to weather forecast so if I go to my new controller so I need to type the controller name it will go to go directly get method so my controller name is this one why okay I need to give that one right HTTP get I can give the route Also let's don't give route here I'm giving route here get YouTube foreign so you can see now it is coming please subscribe to my YouTube channel but if I go to this route there is nothing is there and there are maybe one or two API maybe multiple apis so if there is a big application a legacy application thousands of API so creating this documentation will be a headache so that's why we are going to use Swagger so go to new get package new get package solution we need to R a nuget package that is swas vocal this is a swashbuckle I'm going to add this to our project guys in this project I am going to keep in the drive and give the link so don't worry you can check it out this code so it got okay it got installed now next next dark Stitch go to the program.cs file because you are using dot net core 6.0 here you need to R Builder dot Services Dot or Swagger into our our Swagger Jain before that I need to add Builder dot service dot R endpoint API Explorer now come to the end of here we are going to our up Dot huge Swagger UI right for that we want to use up dot huge Swagger only who didn't configure anything we just added these two method in the Builder dot service are endpoint API Explorer or Swagger gen and in application.ron we have added Swagger and Swagger UI let's run now so let's go to the host only still it is not coming so we need to configure our application to run some UI part so in case of use Swagger UI I am going to write use for the reward option endpoint for the end point what is the abortion and what is the document title next the application now I think we need to do one more time but let's see so this is a root URL so you can see now it is coming my API name and my schemas or my model name right so you can see everything is coming now we can do this thing also in inside our Builder Also let's see in the Builder section how we can in the Builder section in our Swagger gen write like this Builder dot service.orgen option option Swagger dock equal to version one for the title or the new Swagger document what is the version one for the version so here I am running the application so you can see now it is coming fine also but if I want to add some proper summary in my model how I can add this so stop the application from running go to the model so here I am going to add so temperature that temperature in Centigrade or Celsius temperature in Fahrenheit and the temperature summary okay let's run the application and see this properties are coming in the UI documentation or not or if it is not coming we need to do some steps extra Square so these are not coming so how we can do this we need to go to stop this stop this programming go to the program.cs here we need to add some line the app Swagger gen I am going to write bar file name equal to assembly dot get executive assembly.getname so it will come this particular Swagger demo.xml file OK next PATH dot combine.file name and include an option dot include XML then file path so here assembly we need to add system reflection okay now run the application so before that stop the application and see the XML file is there or not containing folder so bin debug we don't have any XML files so definitely this is going to give error to me run the application foreign command only to generate the project XML file so could not find the PATH right so this is or we need to resolve this so how go to the solution Explorer right click on the project go to the properties section inside the general itself come down so you can see here something called generate a file containing API documentation okay save the application now build it XML file we generated in that bin folder this one right my project name.xml now run the application go to this model so you can see temperature there temperature inside Celsius temperature in Fahrenheit temperature in summary we have given this comment inside our model right so while creating the document doesn't also you can create the function for your command line or summary in this way we can Implement Swagger guys if you like this video give me a like and share this video with your friends thank you very much
Info
Channel: Biswa Ranjan
Views: 14,145
Rating: undefined out of 5
Keywords: asp.net core Swagger tutorial, Swagger asp.net core web api, asp.net core Swagger, asp.net core add Swagger, Swagger and asp.net core, asp.net core Swagger config, asp.net core Swagger di, asp.net core Swagger example, asp.net core inject Swagger, asp.net core mvc Swagger, MVC Swagger, .NET Swagger, what is Swagger, Swagger c#, explain Swagger, c# Swagger, c# .net tutorial for beginners, Swagger, Swagger tutorial c#, c# tutorials, c# videos, csharp tutorial
Id: LZBD-ZAKZ0g
Channel Id: undefined
Length: 12min 30sec (750 seconds)
Published: Fri Sep 02 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.