Spring boot - How to Create Interactive API Documentation for your REST API with Swagger? | Swagger

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
this video tutorial i will explain how to create an interactive api documentation for your rest api using sauger if you want to know more about sauger then go to this website swagger simplify api development for users team and enterprises with swagger open source and professional tool set and click on this to explore swagger tools why do we need sauger swagger is used for apa design api development api documentation api testing api mocking and virtualization api governance api monitoring using sogger we can design and model the apis once design is done from the design we can generate the code almost any programming language and then we can create interactive api documentation and also using sauger we can perform a simple functional test on your apis without any overhead and also we can set and enforce apa style guidelines across your api architecture next what we will see is how to integrate sauger with existing restful apa project and how to generate interactive api documentation using sauger and how to use tools like sauger ui to see the apa specification here you can see the example of sagger api documentation once we integrate sauger with your restful apa project and in the top section we can see the description of the project and here you can see the list of endpoints which are supported by this project and here you can see the model details here a post meaning this particular endpoint support http method post and this particular endpoint support http method put click on this and here you can see the request details and what will be the response so all those request and response details here you can see and if you want to test or if you want to give it a try then click on this and here you can provide the pet id and click on execute the request will send to the restful api endpoint and here we got the response now we will see how to add soccer dependencies in our project here you can see springfork's project and it is the implementation of sauger specification and using this we can generate api documentation automatically we will see how to do that if you want to know more about springfox project then go through this url and here you can find quick links like samples release snapshot etc click on reference documentation and you can go through this documentation to understand more about stringfox project to get maven dependency go to this mbnrepository.com and search for spring fox and here you can see spring fox sauger 2 and spring fox sauger ui these two we need and i am going to use 2.9.2 version click on this and here you can see the dependency details and in sauger ui also i am going to use 2.9.2 version and here we got the dependency details this dependency and this dependency i have added in the form.xml file here you can see now we will see how to create sogger configuration file and this sogger configuration file is needed to tell the framework which package it has to scan to find restful web service endpoints and using those restful web service endpoints the api documentation will be created automatically here i have defined the class swagger config and in this class i have applied configuration annotation and enable sogger2 annotation and in this class apa method is there this method returns a docket bin and here i have specified which package it has to scan to find out restful web service endpoints based on that apa documentation will be created automatically and in this package user controller is there and it has various endpoints for creating users getting the users deleting the users etc and based on these endpoints apa documentation will be created next we will see how to enable sogger urls and view json documentation here you can see web security class and it has a configure method and in that we have to add this piece of code so that when we access sogger related urls it won't ask authorization header basically we no need to provide authorization header to access soccer-related urls now i am going to start this spring boot application use this url to access sogger ui here you can see the soccer ui and here you can see the base url and to view the api documentation in json format click on this copy this json paste it here click on viewer and you can view it in the formatted way and here you can see the apa documentation in json format and here you can see the different endpoints supported by the particular spring boot application to understand apa documentation in json format is a bit difficult so we will use swagger ui swagger ua has two sections the first one is user controller and second one is models click on user controller to expand this and to get a list of users we can use this url and http method is get to create the user we can use this url and http method is post and to get the particular user based on the id then we can use this url and http method is get and to update the particular user we can use this url and http method is put to delete the user we can use this url and http method is delete and like that you can see other endpoints click on models and here you can see the models which we have used in our project and to understand the address request model click on this and here you can see each property and the corresponding data type and like that you can click and understand that in user controller there is a create user method is there to call this method we have to use this url and http method is post click on this and here you can see the request details here you can see the sample value which we have to send it to the server in order to create the user and it is in xml format and if you want to change to json select this and you can see the example value in json format and if you want to understand the model click on this and here you can see the model and here you can see the sample response how it will be and it is in xml format if you want to change select json here you can see the sample response in json format and swagger is interactive so if you want to send user create request and create the user that is possible click on try it out and here we have to provide the user details in json format copy this first name is arun last name is p and email address password and it has array of addresses click on execute and here we got the output we got 200 status code and here we got the response body and user is successfully created and this is the public user id and here you can see the response headers we can check it in database click on refresh and here you can see one user record is created and for this user address is also created in addresses table user is successfully created and this is the public user id using this public user id we will see how to get this particular user for that we have to use this url and http method is get click on this and here you can see it accept id parameter and here you can see the sample output click on try it out and here provide the public user id and click on execute and here you can see we got status code as 403 and access denied because we are using a spring security and it is not allowing to get the response back so what we have to do is we have to pass authorization header with jwt token but in the request there is no option to provide the authorization header and we will see how to add authorization header and pass jwt token and get the particular user details now we will see how to add authorization header as a header parameter now i am going to add authorization header parameter in the get user method so in get user method i have applied ap implicit params annotation and here i am passing the parameter name as authorization and value is nothing but description of this parameter and parameter type i am passing as a header parameter type can be a path parameter or query parameter or body parameter or form parameter and to check that open this and here you can see what are the possible parameter type is mentioned here path parameter query parameter body parameter header parameter and form parameter and here we have mentioned header parameter now i am going to start this application open the sogger ui click on this click on get user and here you can see the header parameter authorization is added and here you can see the description and click on try it out and here we have to pass the public user id and here we have to pass the jwt token i have opened the postman and i'm going to send a request to this login url http method is post and in the body i am passing email and the password click on send and here i got the public user id copy this and paste here then then copy the jwt token paste here and response content type change to json then click on execute and here you can see we got status quo as 200 which means successful and here we got the response body we got the details of the user arun list of addresses first name last name and email address so if you see this sogger ui there is no login url to get jwt token it has it users create users only those urls are there there is no login url is there to get the public user id and jwt token like we have done here using postman we will see how to add login url and how to get jwt token and public user id using swagger now we will see how to add a login endpoint here i have defined the class authentication controller which is rust controller and here i have defined the fake login method and this method should not be called because it is implemented by string security and this method we have defined here the purpose for sauger ui to show the login url so that we can send the request from sauger ui and in the parameter i am passing a login request model because in the body we have to pass email and password and here apa operation name is user login and the api responses should return authorization editor and public user id and here is the description for authorization header and response return type should be string now what we will do is we will run the application and see it is working or not click on this url and here you can see authentication controller and here you can see the login url and method should be post and here you can see this is the example value we have to pass and response letter we will get authorization and user id here is the description and here is a type click on try it out copy this so email i am passing around yahoo.com password i am passing pass123 click on execute and status code we got 200 and response letters we got authorization editor which has jwt token and public user id here you can see the public user id now we will see how to configure this api section to configure api info section what we have to do is in sauger config class create apinfo object and in ap info constructor we have to pass title description version terms of service url contact name license and license url here you can see all those things i have passed and in apa method which returns a target object and in that we have to add apa info and this is how we can add ap information in the ap information section and suppose if you want to configure protocols then we have to add protocols like this here i have added http and https now we will start the application and see it is working or not here you can see the ap information section has been configured with whatever details we have provided the title we have provided as user useful web service documentation and that you can see here like that you can see other details also and here we have provided the protocols http and https and that you can see here http and https click on user controller and here you can see http method name part and method name in the user controller i am opening a user controller class and here you can see create user method and get user method the same method name here you can see create user and get user instead of method name i want to provide a proper description and notes we will see how to do that here you can see get user method and in this method i have applied apa operation annotation and here i have provided value value is nothing but description of the web service endpoint and value i have mentioned get user details web service endpoint and notes i have provided this web service endpoint returns user details and need to pass a public user id in the url now i am going to start this application click on refresh and here you can see the description of the web service endpoint instead of method name click on this and here you can see the notes you can get java source code link for each video in the description section of the video here you can see the description section click on show more and here you can see the java source code links click on these links to get the java source code
Info
Channel: Ram N Java
Views: 2,323
Rating: undefined out of 5
Keywords: swagger, swaggera, openapi, swagger ui, swaggerapi, openapi specification, whats swagger, swaggerhub, swagger style, swagger openapi, swagger online, swagger example, openapi example, swaggerdefinition, julie swagger, swagger nodejs, swagger java, swagger npm, openapi 3.0, openapi 3, swagger specification, maven swagger, swagger clothes, swagger view, swagger technology, installing swagger, swagger python, swagger 2.0, swagger ui online, swagger 3, openapi 3.0 example
Id: OVm_1heKCTQ
Channel Id: undefined
Length: 26min 48sec (1608 seconds)
Published: Wed Mar 09 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.