Skip to content

How To Use Postman In Mac

API Testing Blog

Download and Install Postman in Mac

  • Visit the official Postman website: https://www.postman.com/
  • Click on “Download” and select the macOS installer.
  • Double-click the installer file to launch the installation wizard.
  • Follow the on-screen prompts to complete the installation process.

Start Postman on Your Mac

  • Open the Applications folder on your Mac.
  • Locate the Postman app and double-click to launch it.
  • You’ll be presented with the Postman interface, which includes the workspace, request builder, and response viewer.

Create Your First API Request

  • 1. Select HTTP Method: In the request builder, choose the HTTP method you want to use (e.g., GET, POST, PUT, DELETE).
  • 2. Enter Request URL: Type the URL of the API endpoint you want to interact with.
  • 3. Add Headers (Optional): If the API requires specific headers, click on the “Headers” tab and add them.
  • 4. Add Body (Optional): If the request requires a body, click on the “Body” tab and select the appropriate format (e.g., JSON, form-data, etc.).

Example: Sending a GET Request to a Weather API

// Method: GET
// URL: https://api.openweathermap.org/data/2.5/weather?q=London&appid=YOUR_API_KEY
// Headers:
// Content-Type: application/json
// Body: (Leave empty for GET requests)
  • 5. Send Request: Click the “Send” button to execute the request.

View API Response

  • The response from the API will be displayed in the response viewer. You can view the following:
    • Status Code: Indicates the success or failure of the request (e.g., 200 - OK, 404 - Not Found, 500 - Internal Server Error).
    • Headers: Headers returned by the API server.
    • Body: The actual data returned by the API.

Utilize Postman Collections for Organizing API Tests

  • Collections allow you to group and manage multiple API requests together. This is useful for:
    • Creating a structured set of tests for an entire application’s API.
    • Sharing API tests with team members.
    • Running multiple requests in sequence.

Create a New Collection

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

Adding Requests to a Collection

  • Open the request you want to add.
  • Click the “Save” icon and select your collection.

Perform API Testing with Postman’s Features

  • 1. Assertions: Write tests to verify expected values in the API response using assertions.
    • Click the “Tests” tab and add assertions using JavaScript code.

Example: Asserting Status Code in a Request

pm.test("Status code is 200", function () {
pm.response.to.have.status(200);
});
  • 2. Environment Variables: Store sensitive data like API keys or URLs as variables to reuse across multiple requests and collections.
    • Go to the “Manage Environments” section and create a new environment.
    • Add variables with their values (e.g., API_KEY with your actual key).

Example: Using Environment Variables

// Request URL using environment variable:
{{baseUrl}}/weather?q=London&appid={{apiKey}}
  • 3. Pre-Request Scripts: Run JavaScript code before sending a request to perform actions like setting variables or updating headers.

Example: Setting a Header in a Pre-request Script

pm.environment.set("token", "your_token");
pm.request.headers.add("Authorization", "Bearer " + pm.environment.get("token"));
  • 4. Test Runner: Run all requests within a collection sequentially, using assertions to validate responses.
    • Go to the “Runner” tab, select your collection, and click “Run”.

Integrate Postman with Your Development Workflow

  • 1. Postman API: Access Postman features programmatically using the Postman API.

    • This allows you to automate your workflow by integrating Postman with CI/CD systems.
  • 2. Postman Newman: A command-line tool that allows you to run Postman collections from your terminal.

    • Useful for integrating Postman with your testing automation process.
  • 3. Postman for Teams: Collaborate with your team on API testing and documentation.

    • Share collections, workspaces, and environments with team members.

By mastering Postman’s features and integrating them into your development workflow, you can streamline your API testing process and ensure the quality of your applications.

API Testing Blog