Getting Started with Postman



Getting Started with Postman

  1. Install Postman: If you haven't already, download and install Postman from Postman's website.

  2. Import the Petstore API Collection:

    • Open Postman.
    • Click on the "Import" button in the top-left corner.
    • Choose the "Import From Link" tab.
    • Enter the following URL: https://petstore.swagger.io/v2/swagger.json
    • Click "Continue" and then "Import".

Examples of API Testing with the Petstore API

Example 1: GET Request to Retrieve Pet by ID

  1. Endpoint: /pet/{petId}

    • Method: GET
    • URL: https://petstore.swagger.io/v2/pet/1
  2. Steps:

    • In Postman, create a new request.
    • Set the method to GET.
    • Enter the URL: https://petstore.swagger.io/v2/pet/1
    • Click on the "Send" button.
  3. Expected Response:

    {
      "id": 1,
      "category": {
        "id": 1,
        "name": "Dogs"
      },
      "name": "doggie",
      "photoUrls": [
        "string"
      ],
      "tags": [
        {
          "id": 1,
          "name": "tag1"
        }
      ],
      "status": "available"
    }
    

Example 2: POST Request to Add a New Pet

  1. Endpoint: /pet

    • Method: POST
    • URL: https://petstore.swagger.io/v2/pet
    • Request Body:
      {
        "id": 12345,
        "category": {
          "id": 1,
          "name": "Cats"
        },
        "name": "Whiskers",
        "photoUrls": [
          "http://example.com/photo.jpg"
        ],
        "tags": [
          {
            "id": 1,
            "name": "cute"
          }
        ],
        "status": "available"
      }
      
  2. Steps:

    • In Postman, create a new request.
    • Set the method to POST.
    • Enter the URL: https://petstore.swagger.io/v2/pet
    • Go to the "Body" tab and select "raw" and "JSON".
    • Paste the request body JSON.
    • Click on the "Send" button.
  3. Expected Response:

    {
      "id": 12345,
      "category": {
        "id": 1,
        "name": "Cats"
      },
      "name": "Whiskers",
      "photoUrls": [
        "http://example.com/photo.jpg"
      ],
      "tags": [
        {
          "id": 1,
          "name": "cute"
        }
      ],
      "status": "available"
    }
    

Example 3: PUT Request to Update an Existing Pet

  1. Endpoint: /pet

    • Method: PUT
    • URL: https://petstore.swagger.io/v2/pet
    • Request Body:
      {
        "id": 12345,
        "category": {
          "id": 1,
          "name": "Cats"
        },
        "name": "Whiskers Updated",
        "photoUrls": [
          "http://example.com/photo.jpg"
        ],
        "tags": [
          {
            "id": 1,
            "name": "cute"
          }
        ],
        "status": "sold"
      }
      
  2. Steps:

    • In Postman, create a new request.
    • Set the method to PUT.
    • Enter the URL: https://petstore.swagger.io/v2/pet
    • Go to the "Body" tab and select "raw" and "JSON".
    • Paste the request body JSON.
    • Click on the "Send" button.
  3. Expected Response:

    {
      "id": 12345,
      "category": {
        "id": 1,
        "name": "Cats"
      },
      "name": "Whiskers Updated",
      "photoUrls": [
        "http://example.com/photo.jpg"
      ],
      "tags": [
        {
          "id": 1,
          "name": "cute"
        }
      ],
      "status": "sold"
    }
    

Example 4: DELETE Request to Remove a Pet

  1. Endpoint: /pet/{petId}

    • Method: DELETE
    • URL: https://petstore.swagger.io/v2/pet/12345
  2. Steps:

    • In Postman, create a new request.
    • Set the method to DELETE.
    • Enter the URL: https://petstore.swagger.io/v2/pet/12345
    • Click on the "Send" button.
  3. Expected Response:

    • Status code 200 OK with an empty body or confirmation message.

Conclusion

Using Postman to test the Petstore API involves sending HTTP requests to various endpoints and validating the responses. This process helps ensure that the API is functioning correctly according to the specifications. By following these examples, you can start testing your own APIs effectively.

Post a Comment

Previous Post Next Post