How to Use Postman for API Testing

When building or consuming a REST API, you need a tool to test endpoints without having to build a frontend interface first. Postman is the answer to that need — an API testing pla...

How to Use Postman for API Testing

When building or consuming a REST API, you need a tool to test endpoints without having to build a frontend interface first. Postman is the answer to that need — an API testing platform that is very popular among both backend and frontend developers. With Postman, you can send HTTP requests, analyze responses, set environment variables, and even write automated tests.

Installing Postman

Download Postman for free from https://www.postman.com/downloads. It's available for Windows, macOS, and Linux. After installing, create a free account so you can save request collections and access them from other devices.

Sending a GET Request

A GET request is used to retrieve data from an API. In Postman:

  1. Click the New button, then choose Request.
  2. Select the GET method from the dropdown.
  3. Enter the endpoint URL, for example:
https://jsonplaceholder.typicode.com/posts
  1. Click the Send button.
  2. See the JSON response in the bottom panel.

You can also add query parameters in the Params tab:

https://jsonplaceholder.typicode.com/posts?userId=1

Sending a POST Request with a Body

A POST request is used to send data to the server. Select the POST method, enter the URL, then:

  1. Open the Body tab.
  2. Select raw and the JSON format.
  3. Enter the data you want to send:
{
  "title": "New Article",
  "body": "This is the article content",
  "userId": 1
}
  1. Click Send and observe the response from the server.

Adding Headers

Many APIs require special headers, such as Content-Type or an authentication token. Open the Headers tab and add:

Content-Type: application/json
Accept: application/json
Authorization: Bearer eyJhbGciOiJIUzI1NiIs...

Using Environment Variables

Instead of writing the URL or token manually in every request, use environment variables. Create a new environment (click the eye icon in the top right), then add variables:

base_url = https://api.projectname.com
token = Bearer eyJhbGciOiJIUzI1NiIs...

Use those variables in the URL or headers with the double curly brace syntax:

{{base_url}}/api/users
Authorization: {{token}}

This is very useful when switching between development, staging, and production environments.

Organizing Requests in a Collection

A collection is a folder for grouping related requests. Create a collection per module or per project:

  • Auth — Login, Register, Logout.
  • Users — Get All Users, Get User by ID, Update User, Delete User.
  • Products — CRUD product endpoints.

With good organization, a collection can be shared with the whole team so all developers use the same configuration.

Writing Automated Tests

Postman supports writing simple tests using JavaScript in the Tests tab:

pm.test("Status code is 200", function () {
  pm.response.to.have.status(200);
});

pm.test("Response is JSON", function () {
  pm.response.to.be.json;
});

pm.test("User data has a name field", function () {
  var jsonData = pm.response.json();
  pm.expect(jsonData).to.have.property("name");
});

These tests run automatically every time a request is sent, and the results appear in the Test Results tab.

Saving a Response Token for the Next Request

After logging in, you can automatically save the token to an environment variable using a script in the Tests tab:

var response = pm.response.json();
pm.environment.set("token", "Bearer " + response.data.access_token);

This token can then be used directly in other requests via the {{token}} variable.

Conclusion

Postman is a must-have tool for developers working with APIs. With features like collections, environment variables, and automated testing, you can test all your API endpoints in a structured and efficient way. Start by testing simple endpoints, then move up to using environment variables and automated tests for a more professional workflow. Postman also makes team collaboration easier because collections can be exported and shared easily.

postman tutorial testing api postman indonesia cara pakai postman rest api testing api testing tool
Share this article
Back to Blog
🚀 Partner Recommendation

Need Premium Source Code & Business Apps?

Access Laravel applications, POS systems, School Management, Clinic Software, ERP solutions, and ready-to-use premium source code at GudangCode.

GudangCode
  • ✔ Premium Source Code
  • ✔ Ready-to-Use Systems
  • ✔ Lifetime Updates
  • ✔ Lifetime Membership
  • ✔ Daily App Updates
Join Membership →