Documenting our API with the Swagger UI
Having built our REST API and tested it, it is very important to document the API, because you can have a potentially unknown number of customers who will want to use it. Swagger
(https://swagger.io/) is a very useful tool to help you design and document your APIs. Swagger UI employs the OpenAPI
standard and allows us to document our API in code, and at the same time, to publish it via a web-based human-readable interface.
In order to add support for Swagger UI, we need to add two new packages to our project, SwagUI
and SwaggerMarkdown
:
pkg> add SwagUI, SwaggerMarkdown
We will set up the Swagger comments and the API documentation functionality in the routes.jl
file. The routes for the web application remain the same, but the API routes are now augmented with swagger"..."
annotations that are used to build the API documentation. Add using SwagUI, SwaggerMarkdown
to the routes.jl
file, and update the REST API routes as follows...