Saturday, February 17, 2018

Swagger 2 Support for Rest API Documentation

Please follow Rest API Server to see the big picture and GitHub repo details.

Swagger 2 helps in building the documentation for Rest API's. Springfox provides a suite of libraries to support this. To support, Rest API documentation in Spring boot, follow the steps below

Add to Gradle dependencies


The Swagger dependency helps in documenting the Rest API. The second dependency helps in providing a UI to present the set of API's on browser.

Now define the configuration bean

public class SwaggerConfig {            
    public Docket api() { 
        return new Docket(DocumentationType.SWAGGER_2)  

Accessing the page at http://localhost:8080/swagger-ui.html will show the details of API's. To handle authorization from the browser one can use plugin like ModHead in chrome which helps in inserting the headers. (Please remember to add appropriate filters to the profile definition of ModHead)

No comments:

Post a Comment