Swagger is an open source tool whose purpose is to visualize and interact with the API’s resources without having any of the implementation logic in place. It’s automatically generated from your OpenAPI (formerly known as Swagger) Specification, with the visual documentation making it easy for back end implementation and client side consumption.
Click here for more details about Swagger UI tool.
The django-rest-swagger package has been added in the requirements.txt file. We are currently using version 2.2.0.
The rest_framework_swagger package has been added to the INSTALLED_APPS in base.py file. The following Swagger settings have also been added within this file.
# Swagger settings for documentation
SWAGGER_SETTINGS = {
"LOGIN_URL": "rest_framework:login",
"LOGOUT_URL": "rest_framework:logout",
}
The following import has been added in urls.py file:
from rest_framework_swagger.views import get_swagger_view
Then the schema view has been set up with the following code:
schema_view = get_swagger_view(title="ThunderCAT APIs")
In order to access Swagger UI tool and use all its functionalities, make sure that all your containers are running and working well. Once done, you'll be able to access it with the following link:
By default, you will not be connected, so you will only be able to see and manipulate the unprotected APIs.
However, if you login using your super user credentials, you'll be able to see and manipulate all the APIs.
Also, if you login using basic user credentials, you'll only be able to see and manipulate the APIs that you have permission.
The manipulation of the APIs with Swagger UI is very simple and straight forward. Here is how to do so:
-
Choose the API that you want to use and click on "Try it out":
-
Fill in the required information (if needed) and click on "Execute":
-
You have now your response:
For more information about this tool, visit https://swagger.io/.