Skip to content

How To Use Postman In Chrome

API Testing Blog

How to Install and Set up Postman for Chrome

Postman is a powerful API testing tool that allows you to send requests, get responses, and debug APIs. It is available as a Chrome extension and also as a standalone application. Here’s how to get started with Postman in Chrome:

  1. Install the Postman extension: Go to the Chrome Web Store and search for “Postman.” Click “Add to Chrome” and follow the instructions.
  2. Launch Postman: Once installed, you can find the Postman icon in your Chrome toolbar. Click it to launch the app.
  3. Create a new request: Click the “New” button in the top left corner of the Postman window. This will create a new request tab.
  4. Fill in the request details:
    • Method: Choose the HTTP method you want to use (e.g., GET, POST, PUT, DELETE).
    • URL: Enter the API endpoint you want to test.
    • Headers: Add any headers required by the API.
    • Body: If your request requires data, you can add it here.
  5. Send the request: Click the “Send” button to send your API request.

How to Test GET requests with Postman in Chrome

Let’s use a simple example to demonstrate GET requests. Suppose we want to fetch the weather data for a specific city from an API.

  1. Create a new request: Follow steps 1-3 from the previous section.
  2. Set the method and URL:
    • Method: GET
    • URL: https://api.openweathermap.org/data/2.5/weather?q=London&appid=<YOUR_API_KEY> (Remember to replace <YOUR_API_KEY> with your actual OpenWeatherMap API key.)
  3. Send the request: Click the “Send” button.
  4. View the response: The response from the API will be displayed in the “Response” tab. It will contain data about the weather in London.

How to Test POST requests with Postman in Chrome

Let’s create a user using Postman. We will send a POST request including the details in JSON format.

  1. Create a new request: Follow steps 1-3 from the “Install and Set up Postman” section.
  2. Set the method and URL:
    • Method: POST
    • URL: https://reqres.in/api/users
  3. Add the request body:
    • Body: Choose “raw” and select “JSON” from the dropdown.
    • Enter the following JSON data:
      {
      "name": "Jane Doe",
      "job": "Software Engineer"
      }
  4. Send the request: Click the “Send” button.
  5. View the response: The response will include the newly created user’s details, including their ID.

How to Use Environment Variables in Postman for Chrome

Environment variables allow you to store dynamic values that can be used across multiple requests. This is particularly useful when you need to test different environments or when you have sensitive data like API keys.

  1. Create an environment: Click on the “Environments” button in the left sidebar. Click “Add” to create a new environment.
  2. Add variables: Give your environment a name and add variables like BASE_URL and API_KEY.
  3. Use variables in requests: In your request’s URL, headers, or body, use double curly braces to reference the variables (e.g., {{BASE_URL}}/users, {{API_KEY}}).
  4. Select the environment: Before running a request, make sure you have selected the environment you want to use from the dropdown in the top right corner.

Example

// In your environment:
BASE_URL: https://reqres.in/api
// In a GET request:
URL: {{BASE_URL}}/users

How to Create and Run Collections in Postman for Chrome

Collections are a way to organize your API requests. You can group related requests into a collection and run them together.

  1. Create a collection: Click the “Collections” button in the left sidebar. Click “Create” to create a new collection.
  2. Add requests to the collection: Create new requests or add existing requests by dragging them into the collection.
  3. Run the collection: Click the “Run” button in the collection view to run all the requests in the collection.

How to Use Assertions in Postman for Chrome

Assertions allow you to test the response of your API requests and ensure the responses meet your expectations. You can use assertions to check:

  • Status code: Ensure the response has the expected HTTP status code (e.g., 200 for success).
  • Response body: Verify the content of the response body.
  • Headers: Check specific headers in the response.

Example: To check if the response status code is 200, add an assertion to your request:

  1. Go to the “Tests” tab in your request.
  2. Click the “Add a Test” button.
  3. Use the following code:
pm.test("Status code is 200", function () {
pm.response.to.have.status(200);
});

How to Debug APIs Using Postman in Chrome

Postman helps you debug your API requests by providing various tools:

  1. View the response: The “Response” tab displays the response body, headers, and other details.
  2. Preview the response: Use the “Preview” tab to see the response in a presentable format, such as HTML or JSON.
  3. Use the Console: The “Console” tab lets you debug your tests and write JavaScript code to interact with the testing environment.
  4. Send the request again: If you want to investigate a particular issue with an API request, you can re-send the request after making changes in your code.
  5. Use the debugger: You can use Postman’s debugger to step through your code line by line.

API Testing Blog