Skip to content

How To Send Request Using Postman

API Testing Blog

Sending API Requests with Postman: A Comprehensive Guide

Postman is a powerful tool for testing and interacting with APIs. It simplifies the process of sending requests, receiving responses, and analyzing API behavior. Here’s a comprehensive guide on using Postman to send various API requests.

1. Understanding the Basics

Before diving into specific requests, let’s understand the fundamental concepts in Postman:

  • Requests: Requests are the commands you send to an API to interact with its resources. They include:

    • Method: The HTTP verb used (e.g., GET, POST, PUT, DELETE).
    • URL: The endpoint you’re targeting on the API.
    • Headers: Key-value pairs providing additional information about the request.
    • Body: Data sent along with the request, formatted according to the request method.
  • Responses: After sending a request, the API responds with information about the result of the request. Responses include:

    • Status Code: A numerical code indicating the request’s success or failure (e.g., 200: OK, 404: Not Found).
    • Headers: Information about the response itself.
    • Body: The data returned by the API.

2. How to Send a Basic GET Request with Postman

GET requests are used to retrieve data from an API. Example: Fetching a list of users from a fictional ‘users’ API endpoint:

(1) Setting up the Request

  • Open Postman: Start the Postman app.
  • Create a New Request: Click the “New” button or use the shortcut “Ctrl/Cmd + N”.
  • Select HTTP Method: Choose “GET” from the dropdown menu.
  • Enter the URL: Type the API endpoint where you want to send the request, e.g., https://api.example.com/users.

(2) Sending the Request

  • Click “Send”: This sends the GET request.

(3) Viewing the Response

  • Status Code: Verify the “Status Code” (e.g., 200: OK indicates success).
  • Headers: Examine the headers sent back by the API.
  • Body: The response body will contain the list of users (JSON or XML format).

3. How to Send a POST Request with Postman

POST requests are used to create new data in an API. Example: Creating a new user on the same users API endpoint:

(1) Setting up the Request

  • Method: Select “POST” from the dropdown menu.
  • URL: Keep the same endpoint for the users resource: https://api.example.com/users.
  • Body:
    • Select “raw” body: This allows you to enter raw data.

    • Select “JSON” or “XML” format: Based on the API specifications.

    • Paste the request body:

      {
      "name": "John Doe",
      "email": "john.doe@example.com",
      "age": 30
      }

(2) Sending the Request

  • Click “Send”: This sends the POST request with the new user data.

(3) Viewing the Response

  • Status Code: Verify the “Status Code” (e.g., 201: Created indicates successful creation).
  • Headers: Examine the headers.
  • Body: The response body likely contains details about the newly created user.

4. How to Send PUT Requests with Postman

PUT requests are used to update existing data in an API. Example: Updating a user’s email address:

(1) Setting up the Request

  • Method: Select “PUT” from the dropdown menu.
  • URL: Include the specific user ID in the URL: https://api.example.com/users/123.
  • Body:
    • Select “raw” body: Choose “JSON” or “XML” format.

    • Paste the update data:

      {
      "email": "updated.john.doe@example.com"
      }

(2) Sending the Request

  • Click “Send”: This sends the PUT request with the updated data.

(3) Viewing the Response

  • Status Code: Verify the “Status Code” (e.g., 200: OK or 204: No Content indicate success).
  • Headers: Examine the headers.
  • Body: The body may contain the updated user details or be empty.

5. How to Send DELETE Requests with Postman

DELETE requests are used to remove data from an API. Example: Deleting a user with a specific ID:

(1) Setting up the Request

  • Method: Select “DELETE” from the dropdown menu.
  • URL: Include the specific user ID in the URL: https://api.example.com/users/123.
  • Body: DELETE requests typically don’t need a body.

(2) Sending the Request

  • Click “Send”: This sends the DELETE request to remove the user.

(3) Viewing the Response

  • Status Code: Verify the “Status Code” (e.g., 200: OK or 204: No Content indicate successful deletion).
  • Headers: Examine the headers.
  • Body: The body may be empty or contain a success message.

6. How to Use Authorization with Postman

Many APIs require authentication for accessing their resources. Postman provides several authorization methods:

  • Basic Auth: Used to provide username and password in the request headers.
  • Bearer Token: Used to include an authentication token in the Authorization Header.
  • API Key: Used for sending an API key as a header value.
  • OAuth 2.0: Used for more complex authentication workflows.

Example: Using Bearer Tokens:

  1. Go to the “Authorization” tab: In your request.
  2. Select “Bearer Token”: From the dropdown menu.
  3. Paste the Token: Enter the generated token in the “Token” field.
  4. Click “Send”: This sends the request with the Authorization header.

7. Further Exploration: Postman Collections for API Testing

Postman Collections allow you to organize and manage multiple API requests together. Collections can include:

  • Multiple requests for different API endpoints.
  • Variables to easily reuse data or parameters.
  • Environments to manage different API URLs and other configuration settings.
  • Tests to verify the API’s behavior and responses.

Start Building Your Own Collections:

  1. Create a New Collection: Click the “New Collection” button.
  2. Add Requests: Drag and drop or manually add your API requests to the collection.
  3. Organize Requests: Use folders to structure your API interactions.
  4. Define Variables: Use variables to store shared data like URLs, API keys, or user IDs.
  5. Set up Environments: Create different environments for testing different API versions or configurations.
  6. Write Tests: Add tests within your requests to automate validation checks against API responses.

Conclusion: Empowering API Interactions with Postman

Postman is a versatile and powerful tool for sending a wide range of API requests, automating testing, and streamlining your workflow. By learning the fundamentals of creating requests, understanding HTTP methods, and exploring advanced features like collections and authorizations, you can leverage Postman to more effectively test and interact with APIs. Get started and explore Postman to unlock a world of possibilities for your API projects.

API Testing Blog