Skip to content

How To Use Postman In Ubuntu

API Testing Blog

Getting Started with Postman on Ubuntu

Postman is a powerful tool for API testing and a staple for any developer or tester. Here’s a guide on how to use Postman on Ubuntu.

1. Downloading Postman

First, you need to download Postman. You can choose between the desktop application and the web version.

Desktop Application

Web Version

  • Visit the Postman website (https://www.postman.com/).
  • Sign up or log in to your account.
  • You can access Postman directly in your web browser.

2. Installing Postman on Ubuntu

Installing the Desktop Application:

  1. Open the downloaded .deb file using your package manager (e.g., sudo apt install ./postman-linux-x64-*.deb).
  2. Follow the installation instructions.

Installing the Web Version:

No installation is required. Simply access the Postman website using your web browser.

3. Launching Postman

Once installed, you can launch Postman from your applications menu.

4. Setting Up Your First Request

Choose Your HTTP Method: This determines how the request interacts with the API (e.g., GET, POST, PUT, DELETE).

Enter the API Endpoint: This is the URL where the API resides.

Add Request Headers (Optional): Headers provide additional information about the request.

Add Request Body (Optional): The body contains data to be sent to the API.

Example: Sending a GET Request to a Weather API

  1. Open Postman.
  2. Click on the “New” button to create a new request.
  3. Set the HTTP Method to “GET”.
  4. Enter the API Endpoint: https://api.openweathermap.org/data/2.5/weather?q=London&appid=YOUR_API_KEY (replace YOUR_API_KEY with your actual API key).
  5. Click on the Send button.

The response will show the weather data for London in JSON format.

5. Sending a POST Request

Example: Creating a New User on a User Management API

  1. HTTP Method: “POST”
  2. API Endpoint: https://example.com/users
  3. Request Body:
{
"username": "testuser",
"email": "testuser@example.com",
"password": "password123"
}

6. Utilizing Postman Collections

Postman Collections help organize and manage your API requests. You can group requests together, add documentation, and share collections with others.

Creating a Collection:

  1. Click on the “Collections” button.
  2. Click on the “Create Collection” button.
  3. Give your collection a name and description.

Adding Requests to a Collection:

  1. Go to the request you want to add.
  2. Click the “Save” button.
  3. Select the “Save to Collection” option.
  4. Choose the collection you want to add the request to.

7. Using Postman Environments

Postman environments enable you to store and manage variables for your API requests, making it easier to switch between different environments (e.g., development, testing, production).

Creating an Environment:

  1. Click on the “Environments” button.
  2. Click on the “Add Environment” button.
  3. Give your environment a name.
  4. Add variables and their values.

Example: Using an Environment Variable:

  1. In the “Variables” section of the environment, add a variable named “baseUrl” with the value “https://api.example.com”.
  2. In your API request, replace the base URL with: {{baseUrl}}/users.

8. Running Functional Tests with Postman

Postman allows you to write functional tests for your APIs. You can create assertions to check the response data, headers, and status codes.

Example: Testing the Weather API Response:

  1. Go to your GET request for the weather API.
  2. Click on the “Tests” tab.
  3. Add a test:
pm.test("Status code is 200", function () {
pm.response.to.have.status(200);
});
pm.test("Response body contains London", function () {
pm.response.to.have.body("London");
});

9. Generating Code from Postman Requests

Postman can generate code snippets for various languages and frameworks, making it easier to integrate your API requests into your code.

  1. Go to your request.
  2. Click on the “Code” button.
  3. Choose your language and framework.
  4. Copy the generated code snippet.

10. Utilizing Postman Workspaces

Postman workspaces allow you to collaborate with others on API testing. You can create a workspace, invite team members, and share collections and environments.

Creating a Workspace:

  1. Click on the “Workspaces” button.
  2. Click on the “Create Workspace” button.
  3. Choose a workspace type and give it a name.

11. Extending Postman with Plugins

Postman offers various plugins to enhance its functionality, such as support for additional authentication methods, improved documentation, and more.

  1. Click on the “Plugins” icon (puzzle piece) in the sidebar.
  2. Search for plugins and install them.

Conclusion

Postman is a powerful tool for API testing on Ubuntu. It enables you to send requests, organize tests, write assertions, generate code, and collaborate with others. With its features and extensibility, Postman provides a comprehensive solution for API testing throughout the development lifecycle.

API Testing Blog