2. Lack of etiquette and manners is a huge turn off.
Knolx Session
Etiquettes
Punctuality
Respect session timings,
you are requested not to join
sessions after a 5 minutes
threshold post the session
start time.
Feedback
Make sure to submit a
constructive feedback for all
sessions as it is very helpful
for the presenter.
Silent Mode
Keep your mobile devices in
silent mode, feel free to move
out of session in case you
need to attend an urgent call.
Avoid Disturbance
Avoid unwanted chit chat
during the session.
4. What is Swagger?
● Swagger is an open source API documentation framework.
Swagger provides a UI integrated page where all the API
methods are listed and enables the user to test any
method that is required from the UI. Swagger does the
documentation in a conventional way (OpenAPI) which
means it is in a machine-readable language.
● Swagger is used for documenting the REST APIs.
● It provides HTML view of the API documentation with JSON
Support and detailed information on the HTTP Methods.
5. Why do we need API documentation?
● Rest APIs are basically designed to be used in some kind of app.
● In most likely - the team will have either backend API developers
or full stack developers own the APIs.
● The frontend team will integrate the APIs in the application.
● APIs form the data contracts between UI and Backend teams.
6. Hence Proper Documentation
It’s very important to have solid documentation of APIs
Some of the answers that documentation helps in are:
● What are the endpoints URLs?
● What methods to be used?
● What data to be passed?
● What are the mandatory and optional params to the endpoints?
Why do we need API documentation?
7. Swagger helps in documentation
● Using swagger we can create documentation for our APIs
● We make use of Swagger UI
● “Swagger is a set of rules or a specifications for a format
describing REST APIs”
● It provides an easy way to share API documentation among
developers and product managers and QA.
8. Why Swagger ?
Swagger helps users build, document, test and consume RESTful
web services. It can be used with both a top-down and bottom-up API
development approach. In the top-down, or design-first, method, Swagger
can be used to design an API before any code is written.
Also a question arises like :-
Why we should use Swagger instead of postman??
● What is difference between Swagger and postman?
Swagger is an API specification & Postman is an API Client and appropriate for API first development while,
Postman is appropriate for testing such API based on specifications.
Swagger Vs Postman - Knoldus Blogs {https://blog.knoldus.com/swagger-vs-postman/}
9. ❏ What does it do
● It documents your rest apis URL to make it easy to use.
● Exposes your api endpoints.
❏ How does it do
● Spring Boot and Swagger2 play together very well. Just add the
dependencies, one configuration file, and bunch of annotations
and you are ready to go.
10. Technology Stacks
• Spring
• Spring Boot for fast start
• Also possible for Spring REST applications
• Springfox
• For providing the dynamic api-docs
• Swagger UI
• For accessing the api using a browser
12. Swagger Spring-fox
• Provide complete api-docs for every @RestController
• Services
• Supported Verbs (GET/POST/…)
• Request parameters/body
• Response codes + body
• Many customization options (hide attributes, custom data types,
…)
13. Adding Swagger To Spring Boot
● Getting the Swagger 2 Spring
dependency.
● Enabling Swagger in the code.
● Configuring the Swagger.
● Adding details as annotation to APIs.
15. Swagger Enable Swagger/Springfox
Add @EnableSwagger2 to Application
@Configuration
@EnableSwagger2
public class SwaggerConfig {
@Bean
public Docket api() {
return new Docket(DocumentationType. SWAGGER_2)
.select()
.apis(RequestHandlerSelectors .basePackage ("com.hendisantika.springboot.swagger"))
.paths(PathSelectors. any())
.build().apiInfo(apiInfo());
}
• Run your spring application
16. Spring-Fox Annotation
All the Swagger annotations for documenting the controller are self explanatory.
Following are some of the annotation used here :-
1. Controller:
@Api –-> Narrates the description about what in general is the responsibility
of the controller.
2.Operations:
@ApiOperation –-> Narrates the responsibility of the specific method.
@ApiResponse –-> Define error codes .
3.Model:
@ApiModel("description”)
@ApiModelProperty: description + required-flag • @JsonIgnore
17. Swagger UI
Swagger UI allows anyone — be it your development team or your end
consumers — to visualize and interact with the API's resources
without having any of the implementation logic in place.
● Swagger UI used for accessing your complete REST API using a
browser .
● Lists all services directly from the (dynamic) api-docs.
● Always consistent with your API!