Tutorials 6 min read

Swagger UI Tutorial: How to Use Swagger UI for API Testing

Swagger UI is an open-source tool for visualizing and interacting with RESTful APIs. In this tutorial, we'll show you Swagger's basic introduction and how to use Swagger UI to test an API.

Swagger Tutorial: How to Use Swagger UI for API Testing

What is Swagger UI?

Swagger UI is an open-source tool for visualizing and interacting with RESTful APIs (Application Programming Interfaces) that have been documented using the OpenAPI Specification (formerly known as Swagger Specification).

The OpenAPI Specification is a standard format for describing RESTful APIs in a machine-readable format. Swagger UI makes it easy to explore and test these APIs, by providing a user-friendly interface for developers to browse API documentation, test API endpoints, and experiment with different parameters and options.


Swagger UI can be run as a standalone web application, or it can be integrated into existing web applications using a variety of different programming languages and frameworks. It provides a responsive and customizable interface that can be adapted to fit the needs of different teams and projects.

Overall, Swagger UI is a powerful and flexible tool for working with RESTful APIs, and it has become a popular choice among developers and API providers for testing their APIs.

Swagger UI Express

This is a middleware module that can be used to integrate Swagger UI with Node.js and Express.js-based projects. It provides a simple and efficient way to display your Swagger documentation in a web application. Developers can customize the appearance of their API documentation, including changing the colors and fonts, and even integrate additional elements like authentication functions.

Swagger UI Editor

This web-based editor is an intuitive way to define API endpoints and models in the OpenAPI specification format (formerly known as Swagger). Swagger UI Editor makes it easy for developers to design and create Swagger documents systematically, ensuring that API documentation is both accurate and up-to-date.

Swagger UI URL

This is a simple web-based interface that can be used to visualize and interact with API documents hosted on publicly accessible URLs. Developers can use Swagger UI URL to test and debug their REST APIs, as well as demonstrate and share their API documentation with team members and stakeholders.

Swagger UI HTML

This is an HTML template that generates an elegant and interactive web page, allowing users to view and interact with Swagger documentation. Swagger UI HTML is user-friendly and provides an intuitive way to explore and understand complex API documentation. It can be used to generate a customizable webpage for your API documentation, which can be shared with other developers or integrated into your web application.

The Limitation of Swagger UI

Swagger UI is a useful API documentation viewing tool and offers features to help you design and test your APIs, but it's far from being a complete API management tool. Here's why.

  1. Inability to meet extensive API management requirements: Swagger UI is focused on viewing and testing API documentation and does not cover all the features required for API management. There are many aspects of API management such as API lifecycle management, version control, authentication/authorization, performance monitoring, and security management.
  2. Limited team collaboration: Swagger UI presents API documentation as static HTML files, which limits team-wide collaboration and real-time collaboration. Swagger UI alone is limited when multiple developers and stakeholders need to edit and comment at the same time, manage versions and resolve conflicts in API design and change management.
  3. Limited integration and extensibility: Swagger UI is meant to be used on its own, but has limitations in seamless integration and extensibility with other API management tools and development workflows. In API management, it may be necessary to link with various tools and services, such as linking source code repositories, linking with CI/CD tools, and integrating API gateways and monitoring tools.

Despite the above limitations, Swagger UI is a useful tool for developers and users for documenting and testing APIs. However, it should be combined with other tools and services that complement Swagger UI to cover your overall API management needs.

Here we introduce you to Apidog, a more powerful API management tool. As with Swagger UI, you can easily design APIs and generate clean specs, as well as API testing, API mocking, CI/CD, version control, and more. It also integrates API lifecycle management and team collaboration functions, making it a more powerful and complete API tool than Swagger UI.

API management too

Evolution of Swagger UI

OpenAPI 3.0 was released in July 2017, with major updates and improvements over Swagger 2.0. It provides better security, stricter data type validation, and a more flexible data structure definition, making it a better choice for API specification, particularly for large-scale applications and enterprise-level systems.

How to Use Swagger UI to Test an API?

Here's an example of using Swagger UI to document and test an API:

Swagger UI
  1. Create an OpenAPI specification file in YAML format that describes your API endpoints and operations. For example:
yamlCopy codeopenapi: 3.0.0
  title: Example API
  description: An example API for demonstration purposes
  version: 1.0.0
  - url: http://localhost:8080
      summary: Get a list of users
      description: Retrieves a list of all users
          description: A list of users
                type: array
                  type: object
                      type: integer
                      type: string
                      type: string
                      format: email

2. Download and add the Swagger UI library to your project. You can download it from the official Swagger UI GitHub repository or use a package manager like npm to install it.

3. Configure Swagger UI by creating an HTML file that references the Swagger UI library and your OpenAPI specification file. For example:

htmlCopy code<!DOCTYPE html>
  <title>Example API Documentation</title>
  <link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/npm/swagger-ui-dist/swagger-ui.css">
  <script src="https://cdn.jsdelivr.net/npm/swagger-ui-dist/swagger-ui-bundle.js"></script>
    window.onload = function() {
        url: "http://localhost:8080/api-docs",
        dom_id: "#swagger-ui",
        presets: [SwaggerUIBundle.presets.apis],
        layout: "BaseLayout"
  <div id="swagger-ui"></div>

In this example, the Swagger url property in the SwaggerUIBundle configuration object points to the location of your OpenAPI specification file.

Start your API application and open the Swagger UI HTML file in a web browser. You should see a user-friendly interface that displays your API documentation and allows you to test your API endpoints.

Swagger UI is an essential tool for simplifying the documentation and testing of APIs, making them more user-friendly and convenient. However, while Swagger UI provides basic API specification generation and endpoint testing functionality, it may not be sufficient for more sophisticated testing needs such as scenario testing, continuous integration, and delivery(CI/CD), and performance testing.

For these advanced features, we recommend leveraging a more comprehensive API management platform such as Apidog. Apidog provides a powerful suite of tools that enable you to build and deliver high-quality APIs more efficiently and effectively, improving overall productivity and accelerating project success.

Apidog - An integrated platform for API design, debugging, development, mock, and testing
Download the Apidog API management tool here. Perfectly compatible with macOS, Windows, and Linux. Web version is also available.

FAQs About Swagger UI

What is the difference between Swagger and Swagger UI?

Swagger and Swagger UI are related but different tools.

Swagger is an API specification, and Swagger UI is a tool for visualizing and interacting with that specification. Swagger UI generates documentation based on the Swagger specification and provides an interactive UI for testing APIs and experimenting with different parameters and options. Using these two tools together can improve API development efficiency.

Is Swagger UI free?

Yes, Swagger UI is free and open-source software released under Apache License 2.0. This means that it can be used, modified, and distributed freely, even for commercial purposes.

What is Swagger UI used for?

Swagger UI is used for testing, documenting, and visualizing RESTful APIs in an intuitive and user-friendly interface. It simplifies the development process, increases efficiency, and enhances user experience when consuming APIs. By providing detailed documentation and live representation of an API's responses, Swagger UI is a valuable tool for developers, engineers, and technical writers.

Join Apidog's Newsletter

Subscribe to stay updated and receive the latest viewpoints anytime.