Standard testing and documentation tool for REST APIs: OAS (Open API Specification) and Swagger
OpenAPI Specification (OAS)
- The OAS is an open standard (spec) for describing, documenting, and testing RESTful APIs.
- It provides a machine-readable representation of an API, allowing developers to understand its endpoints, request/response data formats (payloads), authentication methods, etc.
- The specification is written in YAML (Yet Another Markup Language) or JSON format and serves as a contract between the API provider (REST server) and its consumer (REST client).
- It is widely used in the industry to build, test, and consume APIs, supplying better communication and collaboration between development teams.
Swagger
- Swagger is a collection of open-source tools (e.g.,
swagger-ui
) that support this specification and provide additional functionalities like API documentation and code generation.
- Swagger is an open-source set of tools built around the OpenAPI Specification.
How to use?
1.1 Add Swagger dependency in pom.xml
(Already added in Spring Boot backend template project)
<!-- Swagger UI -->
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-ui</artifactId>
<version>2.8.9</version>
</dependency>
1.2 From web browser, access Swagger endpoint
<http://localhost:8080/swagger-ui/index.html>