1. Overview

In this article, we’ll see how to import Swagger APIs to Postman.

2. Swagger and OpenAPI

Swagger is an open-source set of rules, specifications, and tools for developing and describing REST APIs. However, post-2021, OpenAPI refers to the industry-standard specifications, whereas Swagger refers to the tooling.

3. Postman

Postman is an API platform for building and using APIs. Postman simplifies each step of the API lifecycle and streamlines collaboration. We can use Postman to test our API without writing any code.

We can use either the standalone app or the browser extension.

4. Application

We can work with any existing application, or we can create a simple application from scratch that exposes REST APIs.

4.1. Maven Dependencies

We need to add a couple of dependencies for using Swagger with the Swagger-UI:

<dependency>
    <groupId>io.springfox</groupId>
    <artifactId>springfox-swagger2</artifactId>
    <version>3.0.0</version>
</dependency>
<dependency>
    <groupId>io.springfox</groupId>
    <artifactId>springfox-swagger-ui</artifactId>
    <version>3.0.0</version>
</dependency>

4.2. Java Configuration

Swagger can be as easy to configure as:

@Configuration
public class SpringFoxConfig {
    @Bean
    public Docket api() {
        return new Docket(DocumentationType.SWAGGER_2)
          .select()
          .apis(RequestHandlerSelectors.any())
          .paths(PathSelectors.any())
          .build();
    }
}

When we start the application, we can check the Swagger-UI and find the REST API description per controller:

Swagger-UI

 

We can also check the API docs that are generated for our REST APIs:

Swagger-API_Docs

5. Importing into Postman

There are multiple ways to import the APIs into Postman, but in most cases, it requires that the Swagger or OpenAPI definition be available in some text format (for example, JSON).

We can open Postman and navigate to the APIs option on the left, then click on Import to see the different options available:

Postman API Import

5.1. Importing File

If we have a Swagger JSON file available, we can import it via the file option in Postman:

Postman API Import File

 

If we have the Swagger-UI link, we can directly use the link to import the API into Postman.

Copy the API link from Swagger-UI as below:

Swagger Copy Link

And import it via the same link from Postman:

Postman API Import Link

 

5.3. Importing via Raw Text

We can also just paste the JSON as raw text to import the APIs:

Postman API Import Raw Text

 

5.4. Importing via Code Repository

To import APIs from repositories, we need to be logged in to Postman. To import from GitHub, as an example, let’s follow the below steps:

  1. Navigate to the Code Repository tab.
  2. Click on GitHub.
  3. Confirm the GitHub account and authorize postmanlabs to access repositories. Once done, return to the Postman application for further steps.
  4. On Postman, select the organization, repository, and branch and click Continue.
  5. Confirm the APIs we need to import and click Import.

6. Conclusion

In this article, we’ve looked into different ways to import our REST APIs into Postman.

Course – LS (cat=Spring)

Get started with Spring and Spring Boot, through the Learn Spring course:

>> THE COURSE
res – REST with Spring (eBook) (everywhere)
Comments are closed on this article!