As you already know data scientist usually works mostly on the API endpoints. These endpoints give some responses in a structure or formatted object. JSON is one of the most used formats to get and post the responses through the endpoint. But the major problem I have found is how to document them so that each team member in a project can understand them easily. There are various tools for API documentation. But the popular one is SWAGGER. In this post, you will learn how to install and use Swagger locally.
What is Swagger?
Swagger is a tool that helps you to design, build better APIs, and document it throughout the API lifecycle. Such that any developer can use the APIs effortlessly. You can think of it as a tool to build and follow a design approach, such that these APIs can easily integrate with the web, mobile, and other third-party applications easily. Swagger is available in both free and pro versions. The Swagger Editor, Swagger UI, and Swagger Codegen are free and open-source tools while Swagger Hub is free for one user and paid for organizations and teams. Swagger Inspector is for testing the API endpoints in the cloud and it is paid. In this post, you will learn only to install Swagger Editor and Swagger UI.
How to Install Swagger Locally?
In this section, you will learn how to install Swagger Editor and Swagger UI in your operating system step by step.
Step 1: Download and Install NodeJs
Step 2: Download the Swagger Editor and UI
You can directly install the Swagger using the npm command but installing it requires some other commands that you don’t remember. Therefore the best way is to install it using the source code. Go to the official Swagger GitHub page. There you will find the swagger-UI and swagger-editor links. Click on them and download the latest releases.
Step 3: Install the HTTPS Server
You have to first install the Sever as localhost to run the Swagger Editor and UI. Open your command prompt and type the following command
npm install -g http-server
Step 4: Install and Build the Source Code
For installation you can use any terminal or command prompt. Here I am using Windows Command prompt for building the source code. Unzip the download Swagger Editor and go, inside, the folder, and type the following command
It will take some minutes to install the source code.
Step 5: Run the Swagger Editor
After installing the Swagger editor locally now type the following command to start a server for the editor
Hurray, You have successfully installed the Swagger Editor and easily deployed it on your local host. In the same way, you can use the same commands to install and run the Swagger UI locally.
Installation of Swagger UI
How to install Swagger in Ubuntu
You can install Swagger in ubuntu in Ubuntu. To do so you have to run the following lines of code.
npm install -g http-server git clone https://github.com/swagger-api/swagger-editor.git http-server -p 8080 swagger-editor
It will successfully launch the editor on port 8080. But make sure the port must not occupied by the other services.
Fast API uses Swagger UI
You will very excited to know that Now you can automatically make documentation of API endpoints using Swagger. There is a Python package Fast API that allows you to make endpoints with documentation. Documentation of the endpoints is easily created by using the wrapper above the function. If you have already knowledge of Flaks then it’s very easy to learn Fast API.
Swagger Editor vs Swagger UI
There are many readers who get confused with the Swagger Editor and Swagger UI. Here you will know the difference between the Swagger Editor and Swagger UI.
Swagger Editor is an editor where you are able to write OpenApi definitions manually. The file you will save after editing will be of type Yaml or JSON. OpenApi definitions check any syntax error inside the YAML file.
You can consider Swagger UI as an HTML page. Here all the OpenAPI definitions are rendered in the HTML page and the swagger UI generates API documentation according to the definitions.
Data Science Learner Team
Join our list
Subscribe to our mailing list and get interesting stuff and updates to your email inbox.