Skip to content

How To Use Postman Tool In Chrome

API Testing Blog

Setting Up Postman

Postman is a powerful tool for API testing and can be used as a Chrome extension or as a standalone application. Here’s a step-by-step guide to get started with Postman:

1. Downloading and Installing Postman

  • Visit the official Postman website: https://www.postman.com/
  • Click on the “Download” button and choose the appropriate version for your operating system (Windows, macOS, Linux).
  • Follow the installation instructions and launch Postman once it’s installed.

2. Accessing Postman as a Chrome Extension

  • Open your Chrome browser and go to the Chrome Web Store: https://chrome.google.com/webstore/category/extensions
  • Search for “Postman” and click on the official Postman extension.
  • Click on the “Add to Chrome” button to install the extension.
  • You’ll find the Postman icon in your browser’s toolbar.

Sending Your First Request: A Practical Example

3. Sending a Simple GET Request

  • Open Postman and click on the “New” button to create a new request.
  • In the request builder, select the “GET” method from the dropdown.
  • Enter the URL of the API endpoint you want to test in the address bar. For example: https://reqres.in/api/users
  • Click on “Send” to execute the request.

Sample Code:

GET https://reqres.in/api/users
  • The response from the API will be displayed in the response tab, including the status code, headers, and body.

4. Adding Headers

  • You can specify headers in the “Headers” tab of the request builder.
  • For example, to send an Authorization header with a bearer token:
Authorization: Bearer your_token_here

Sample Code:

GET https://reqres.in/api/users
Authorization: Bearer your_token_here

5. Sending a POST Request with Body Data

  • Select the “POST” method from the dropdown.
  • Enter the URL of the API endpoint.
  • In the “Body” tab, select the desired data format (raw, form-data, x-www-form-urlencoded, binary, etc.).
  • Add your JSON data in the request body.

Sample Code:

POST https://reqres.in/api/users
{
"name": "morpheus",
"job": "leader"
}

Working with Collections: Organizing Your Tests

6. Creating Collections

  • Collections help you organize your API requests.
  • Click on the “Collections” tab and then click on the “Create Collection” button.
  • Give your collection a name and description.

7. Adding Requests to Collections

  • You can easily add your existing requests to a collection.
  • Select the request you want to add and click on the “Add to Collection” button.
  • Choose the existing collection you want to add it to.

Exploring Postman Features: Enhancing Your Testing Workflow

8. Environment Variables: Simplifying API Testing

  • Environment variables allow you to store your API keys, base URLs, and other sensitive data in a separate location, making it easier to manage and switch between different environments (development, testing, production).
  • Go to the “Environments” tab and create a new environment.
  • Define your variables and values.
  • You can then use these variables in your requests using curly braces: {{your_variable_name}}.

Sample Code:

GET {{base_url}}/api/users
Authorization: Bearer {{api_key}}

9. Assertions: Verifying API Responses

  • Assertions allow you to check if the API response meets your expectations.
  • Go to the “Tests” tab in the request builder.
  • Write your test assertions using the Postman’s built-in JavaScript library.

Sample Code:

pm.test("Status code is 200", function () {
pm.response.to.have.status(200);
});
pm.test("Response body has a name property", function () {
pm.expect(pm.response.json().name).to.be.a('string');
});

10. Scripts: Automating Your Tests

  • Scripts can further automate your testing process by adding custom logic before sending requests, after receiving responses, or in other parts of the workflow.
  • You can create scripts in the “Pre-request Script” and “Tests” tabs.

Sample Code:

// In Pre-request Script Tab:
console.log("This runs before the request is sent.");
// In Tests Tab
pm.test("Status code is 200", function () {
pm.response.to.have.status(200);
});

By mastering these core features, you can unlock the full potential of Postman for your API testing needs, effectively designing and executing robust tests to ensure your APIs are functioning correctly and efficiently. Remember to experiment with different features and explore the extensive documentation and community resources available to further enhance your knowledge and skills.

API Testing Blog