Import Swagger APIs Into Postman Collection

Introduction

This article will be sharing the key points about the postman collection and how we can easily convert the swagger JSON document into a postman collection. Before taking a deep dive into this let me give you a brief introduction to Postman and its usage.

What is Postman and its usage?

Postman is an API client that makes it easy for developers to create, share, test, and document APIs. This is done by allowing users to create and save simple and complex HTTP/s requests, as well as read their responses. The result - more efficient and less tedious work.

In case you don’t have Postman installed, you’ll need to download it and install it.

Using Postman to execute APIs

Import Swagger APIs Into Postman Collection

According to the image, here is a clear description for each point,

  • Select the appropriate HTTP Methods(Get, Post, Put, Delete) from the dropdown 
  • Adding the Endpoint URL - API Url
  • Hit the Send button to see the response below with the Status code.
  • JSON output.

Here I have a sample API project in my machine with four APIs which are entirely built upon the .Net 5.0, the latest .Net framework released from Microsoft. We can choose any APIs which are built upon any language or framework but the only thing is to make sure those APIs are configured with Swagger because swagger is our main key resource.

Below is my swagger URL which is running on localhost.

Import Swagger APIs Into Postman Collection

Note
URL may differ, as currently, I am running in localhost

Swagger URL - https://{localhost:PortNo}/swagger/index.html

Click on the above-highlighted link where it will take us through another page with having the detailed JSON document of our APIs or else type in the URL where it will open up the JSON document.

Swagger Json-Document - https://{localhost:PortNo}/swagger/v1/swagger.json

{
  "openapi": "3.0.1",
  "info": {
    "title": "WebAPI",
    "version": "v1"
  },
  "paths": {
    "/api/GetAllCustomer": {
      "get": {
        "tags": [
          "Customer"
        ],
        "responses": {
          "200": {
            "description": "Success"
          }
        }
      }
    },
    "/api/CreateCustomer": {
      "post": {
        "tags": [
          "Customer"
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/Customer"
              }
            },
            "text/json": {
              "schema": {
                "$ref": "#/components/schemas/Customer"
              }
            },
            "application/*+json": {
              "schema": {
                "$ref": "#/components/schemas/Customer"
              }
            }
          },
          "required": true
        },
        "responses": {
          "200": {
            "description": "Success"
          }
        }
      }
    },
    "/api/UpdateCustomer": {
      "put": {
        "tags": [
          "Customer"
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/Customer"
              }
            },
            "text/json": {
              "schema": {
                "$ref": "#/components/schemas/Customer"
              }
            },
            "application/*+json": {
              "schema": {
                "$ref": "#/components/schemas/Customer"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Success"
          }
        }
      }
    },
    "/api/Delete": {
      "delete": {
        "tags": [
          "Customer"
        ],
        "parameters": [
          {
            "name": "Id",
            "in": "query",
            "schema": {
              "type": "integer",
              "format": "int32"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success"
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "Customer": {
        "type": "object",
        "properties": {
          "id": {
            "type": "integer",
            "format": "int32"
          },
          "createdDate": {
            "type": "string",
            "format": "date-time"
          },
          "modifiedDate": {
            "type": "string",
            "format": "date-time"
          },
          "isActive": {
            "type": "boolean"
          },
          "firstName": {
            "type": "string",
            "nullable": true
          },
          "lastName": {
            "type": "string",
            "nullable": true
          },
          "contactNumber": {
            "type": "string",
            "nullable": true
          }
        },
        "additionalProperties": false
      }
    }
  }
}

Postman Collection

Step 1

Open Post man > Import (Top left corner).

Step 2

Click on the link tab and paste the swagger JSON document link and click Continue.

Import Swagger APIs Into Postman Collection

 A new popup will open to check the format and collection type..no need to change anything in this popup...Click on Import.

Import Swagger APIs Into Postman Collection

In the Top left menu click on the API button and there in the right corner you can see the list of the APIs that have been created in the postman collection from the swagger JSON URL. To test the API, Click on the open request option from any of the API in the middle layer.

Another way of Importing the Swagger Documentation

Suppose if we already have JSON Documentation for our APIs; here is a simple step to add the JSON inside the Raw text to generate our API collection in Postman.

Import Swagger APIs Into Postman Collection

Conclusion

I hope this article gives you a clear understanding of converting the swagger APIs into Postman collection and how postman is a great tool in order to test our APIs, and it also gives features like publishing the same collection to other platforms.

Thank you for reading, please let me know your questions, thoughts, or feedback in the comments section. I appreciate your feedback and encouragement.

Keep learning....!


Similar Articles