In this video code decode have explained rest api interview questions for experienced candidate along with swagger implementation.
Udemy Course of Code Decode on Microservice k8s AWS CICD link:
Course Description Video :
Rest Api part 2 :
How Do you share REST API contracts you created with Front end team?
There are multiple ways to share the created Rest API contract with front end or any other backend team who wants to access your service.
You can share the CURL from postman.
Best practice is to Implement the Swagger and configure it in such a way that as soon as you start your server the APIs must be automatically documented in Swagger UI.
What is SWAGGER
Documentation From Your API Design
As your project grows with the time, The number of rest end points to fulfilment new functionalities also increases. And so does the headache of maintaining API docs
Swagger tools takes the hard work out of generating and maintaining your API docs, ensuring your documentation stays up-to-date as your API evolves.
For existing APIs: Documentation can be auto-generated from an API definition.
For new APIs - on startup that too will be auto generated.
You can maintain multiple versions too.
What is SWAGGER UI
Swagger UI allows
Developers
Front end team members
Other Service users who calls your Rest endpoints for some data / functionality
to visualize and interact with the API’s resources without having any of the implementation logic in place
Understanding Code
- Enables Springfox swagger 2
return new Docket(DocumentationType.SWAGGER_2) - Springfox’s, primary api configuration mechanism is initialized for swagger specification 2.0
groupName("public-api") - Docket helps configure a subset of the services to be documented and groups them by name. Like - public-api , private-apis, business-api, admin-specific-apis
apiInfo(apiInfo()) - return ApiInfoBuilder - Builds the api information - like title, description, version, license etc.
select() - select() returns an instance of ApiSelectorBuilder to give fine grained control over the endpoints exposed via swagger.
apis() allows selection of RequestHandler's using a predicate. The example here uses an any predicate (default). Out of the box predicates provided are any, none, withClassAnnotation, withMethodAnnotation and basePackage.
Steps used - Summarize
add dependency in POM file in Rest API demo project
Add swagger config file in Rest API demo project
3) Hit :
4) now u see
Basic error controller :
configure Swagger in a Spring Boot application to hide paths exposed by the BasicErrorController.
solutions'
1) 4.1. Exclude with basePackage()
//.apis(RequestHandlerSelectors.basePackage("com.codedecode.demo.controller"))
2) I think, the most elegant solution is to include only controllers into swagger, only thing to bear in mind, is to annotate all the REST controllers with that annotation:
.apis(RequestHandlerSelectors.withClassAnnotation(RestController.class))
As BasicErrorController is annotated with only, swagger would avoid BasicErrorController in definition file in Rest APi demo project
Most Asked Core Java Interview Questions and Answers :
Advance Java Interview Questions and Answers :
Java 8 Interview Questions and Answers :
Hibernate Interview Questions and Answers :
Spring Boot Interview Questions and Answers :
Angular Playlist :
SQL Playlist :
GIT :
Subscriber and Follow Code Decode
Subscriber Code Decode :
LinkedIn :
Instagram :