You can use Swagger to document your REST API, it's not difficult to set up. There are some instructions here. To summarize:
Adding Swagger dependencies
Add the following dependency to your pom.xml
:
<dependency>
<groupId>io.swagger</groupId>
<artifactId>swagger-jersey2-jaxrs</artifactId>
<version>1.5.0</version>
</dependency>
Setting up Swagger
Add the following to your Application
class (change the values according to your needs):
@ApplicationPath("/api")
public class MyApplication extends Application {
public MyApplication() {
BeanConfig beanConfig = new BeanConfig();
beanConfig.setVersion("1.0");
beanConfig.setSchemes(new String[]{"http"});
beanConfig.setHost("localhost:8080");
beanConfig.setBasePath("/api");
beanConfig.setResourcePackage("io.swagger.resources,com.example.project");
beanConfig.setScan(true);
}
}
Build your project, start your server and access http://localhost:8080/app/api/swagger.json
(the URL might be different in your environment) to get the JSON which documents your API.
Setting up Swagger UI
Download Swagger UI from GitHub and copy the content from the dist
folder to your web content folder. I usually create a folder called api-docs
to store all Swagger UI files.
Open Swagger UI's index.html
and change the URL which refers to the swagger.json
:
var swaggerUi = new SwaggerUi({
url: "http://localhost:8080/app/api/swagger.json",
dom_id: "swagger-ui-container"
});
Access http://localhost:8080/app/api-docs
(the URL might be different in your environment). The Swagger UI with your API documentation should be there.
More information