Skip to content

How To Use Postman Linux

API Testing Blog

Getting Started with Postman on Linux

Postman is a powerful tool for API testing, and its versatility extends to Linux environments. Whether you’re a seasoned developer or new to API testing, this guide will walk you through the process of setting up and using Postman on Linux.

Installing Postman on Linux

There are two main ways to get Postman on your Linux system:

  1. Download & Install the Desktop App:

    • Visit https://www.postman.com/downloads/ and select the Linux installer.
    • Download the package and run it using the terminal.
    • Follow the on-screen instructions to complete the installation.
  2. Using Snapcraft:

    • Open your terminal and run the following command:
      Terminal window
      sudo snap install postman
    • This will download and install the latest version of Postman from the Snap Store.

Creating Your First Request

Once Postman is installed, you’re ready to send your first API request. Here’s how:

  1. Open Postman: Launch the Postman application.
  2. Create a New Request: On the home screen, click “Create a Request”.
  3. Select the HTTP Method: Choose the appropriate HTTP method for your request (e.g., GET, POST, PUT, DELETE).
  4. Enter the Request URL: Enter the URL of the API endpoint you want to target.
  5. Sending the Request: Click the “Send” button to execute your request.

Example: Getting data from a public API

Let’s retrieve data from the JSONPlaceholder API.

  1. Open the Postman App
  2. Create New Request:
    • Method: GET
    • URL: https://jsonplaceholder.typicode.com/posts
  3. Send the Request: Click “Send.”
  4. Review the Response: You will see the response data in the “Body” tab. This will be a JSON array containing multiple posts.

Working with Request Parameters

Many APIs require additional information to be passed within the request. Postman provides various methods to manage parameters:

Query Parameters

  • Adding parameters: In the “Params” tab of your request, add a new parameter by clicking the ”+ Add param” button. Specify the parameter name and value.
  • Example: Filtering posts:
    • URL: https://jsonplaceholder.typicode.com/posts
    • Params: userId=1
    • This will retrieve posts only from user with ID 1.

Headers

Headers provide additional metadata about the request.

  • Adding headers: Go to the “Headers” tab and click the ”+ Add header” button. Enter the header name (e.g., Authorization) and its value.

Body Data

  • Sending JSON data:
    • Method: POST.
    • URL: https://jsonplaceholder.typicode.com/posts
    • Body: In the “Body” tab, select “raw” and paste the following JSON:
      {
      "userId": 1,
      "title": "New Post",
      "body": "This is a sample post."
      }
    • Send the request. You will receive a new post with the provided data.

Using Environment Variables

Environment variables allow you to manage and reuse URL and parameter values across multiple requests.

  • Create an Environment:
    • Go to “Environments” in the side menu, click “Add” to create a new environment.
    • Set a name (e.g., Production) and add variables (e.g., BASE_URL, API_KEY) along with their corresponding values.
  • Using an Environment:
    • Choose the environment from the dropdown in the top right of the Postman interface.
    • In your request, use the syntax {{variableName}} to reference environment variables. For example:
      • {{BASE_URL}}/api/users

Creating Collections

Collections in Postman help you organize and manage groups of related API requests.

  • Create a New Collection: Click the “Collections” button in the sidebar and select “Create Collection.”
  • Add Requests: Drag and drop requests into the collection, or click ”+ Add request” to create new requests within the collection.
  • Organize Collections: Use folders within collections to further structure your requests.

Utilizing Postman’s Features

  • Testing and Assertions: Postman provides powerful tools for validating API responses. You can use test scripts to define assertions and verify the behavior of your APIs. For example:

    pm.test("Status code is 200", function () {
    pm.response.to.have.status(200);
    });
    pm.test("Body contains the correct message", function () {
    pm.expect(pm.response.text()).to.include("success");
    });
  • Running Collections: Postman allows you to run collections in sequence or use iterations. This is particularly helpful for complex API workflows.

  • Creating Workspaces: Workspaces provide a collaborative environment for teams to share and manage API testing efforts.

Postman on Linux: A Comprehensive Solution

The intuitive interface, flexible features, and cross-platform compatibility of Postman make it a top choice for API testing on Linux. Whether you’re working on a personal project or part of a large development team, utilizing Postman’s capabilities will enhance your API development and testing workflow.

API Testing Blog