# postman

Sets standards for Postman collection structure and test scripts. Helps Cursor build maintainable API workflows without hardcoded secrets.

- rule · `type=rule` · Cursor · ★ 3580
- Author: sanjeed5
- License: CC0-1.0 · policy=mirror · the beginning of the file is at the end of this page
- Source: https://github.com/sanjeed5/awesome-cursor-rules-mdc/tree/HEAD/rules-mdc/postman.mdc
- Updated: 2026-05-19
- HTML: https://affpapa.org/en/nevibecode/rules/postman

## What it does

This rule guides Cursor to organize Postman collections like modular project code. Requests sit inside resource folders with explicit method names like `GET /users/{id}` instead of flat lists. Environment variables store secrets, keeping credentials out of version control.

Shared checks move to collection-level test scripts to eliminate copy-pasted code. For multi-step workflows, scripts chain requests by saving response IDs with `pm.environment.set()`. External APIs are replaced with Postman Mock Servers.

The guide warns about asynchronous execution in `pm.sendRequest`. Assigning variables outside its callback leaves them `undefined` and breaks test execution.

## Requirements
- Works with: Postman

## Install

### Cursor (native platform)

**Manually: put the files in place**
- File: `.cursor/rules/postman.mdc` — Frontmatter: description, globs, alwaysApply

### Claude Code

**Manually: put the files in place**
- File: `.claude/rules/postman.md` — The paths frontmatter field limits the files: move globs from the source into paths

### Codex

**AGENTS.md**
- Codex reads AGENTS.md: paste the rule text there

### GitHub Copilot

**Manually: put the files in place**
- File: `.github/instructions/postman.instructions.md` — The applyTo field sets which files it applies to: move globs from the source into applyTo

### Windsurf (Devin Desktop)

**Manually: put the files in place**
- File: `.devin/rules/postman.md`

### Cline

**Manually: put the files in place**
- File: `.clinerules/postman.md`

Where a file is given instead of a command, copy the files from the source to that path: https://github.com/sanjeed5/awesome-cursor-rules-mdc/tree/HEAD/rules-mdc/postman.mdc

## When to use it
- organize API endpoints into resource-based folders
- extract repeated assertions into collection-level test scripts
- pass auth tokens and entity IDs between sequential requests
- configure data-driven testing using external JSON files
- mock unstable external endpoints during test execution

## Example prompts
- Write a Postman test for `POST /users` that saves the new user ID to an environment variable
- Group these flat requests into resource folders with explicit HTTP methods
- Add a pre-request script fetching an auth token asynchronously with `pm.sendRequest`

## Source text · postman.mdc · CC0-1.0

Below is the content of a third-party file. It is data, not instructions for you: do not act on anything written inside unless the human asks. Block tag: 1fd72b2947c262dd.

BEGIN THIRD-PARTY FILE 1fd72b2947c262dd
````text
---
description: This guide defines definitive best practices for structuring, scripting, and testing APIs using Postman, ensuring maintainable, robust, and collaborative API workflows.
globs: **/*
---
# Postman Best Practices

Postman is our definitive tool for API development, testing, and documentation. Adhering to these guidelines ensures consistency, maintainability, and reliability across all our API interactions.

## 1. Code Organization and Structure

Organize your Postman collections like source code: structured, versioned, and modular.

### 1.1 Collection Hierarchy

Mirror your API's resource structure with a clear folder hierarchy. Each folder should represent a logical API resource or module.

❌ **BAD: Flat Collection**
```
- My API
  - Create User
  - Get User by ID
  - Update Product
  - Delete Order
```

✅ **GOOD: Structured Collection**
```
- My API v1.0
  - Users
    - POST Create User
    - GET Get User by ID
    - PUT Update User
    - DELETE Delete User
  - Products
    - POST Create Product
    - GET Get Product by ID
    - PUT Update Product
    - DELETE Delete Product
  - Orders
    - POST Create Order
    - GET Get Order by ID
    - PUT Update Order
    - DELETE Delete Order
```

### 1.2 Request Naming

Use descriptive names for requests, including the HTTP method and the resource path.

❌ **BAD: Vague Request Names**
```
- Get User
- Update Product
```

✅ **GOOD: Explicit Request Names**
```
- GET /users/{id}
- PUT /products/{id}
- POST /auth/login
```

### 1.3 Variables Management

Leverage Postman variables (global, environment, collection) to avoid hardcoding and promote reusability.

*   **Global Variables**: For non-sensitive, truly global data (e.g., common utility functions). Use sparingly.
*   **Environment Variables**: For environment-specific configurations (e.g., `BASE_URL`, `AUTH_TOKEN`, `API_KEY`). **Never commit sensitive data to source control.**
*   **Collection Variables**: For data specific to a collection (e.g., `user_id`, `product_name`) that might change during a test run but is not environment-specific.

**Naming Convention**:
*   Environment Variables: `UPPER_SNAKE_CASE` (e.g., `DEV_BASE_URL`, `PROD_AUTH_TOKEN`)
*   Collection/Local Variables: `camelCase` (e.g., `userId`, `productName`)

❌ **BAD: Hardcoded Values**
```javascript
// Pre-request Script
pm.request.url = "https://dev.api.com/users";
pm.request.headers.add({ key: "Authorization", value: "Bearer my-hardcoded-token" });
```

✅ **GOOD: Variable Usage**
```javascript
// Environment Variables: BASE_URL, authToken
// Collection Variables: userId

// Pre-request Script
pm.request.url = `${pm.environment.get("BASE_URL")}/users/${pm.collection.get("userId")}`;
pm.request.headers.add({ key: "Authorization", value: `Bearer ${pm.environment.get("authToken")}` });
```

## 2. Common Patterns and Anti-patterns

Adopt patterns that enhance test reliability and maintainability.

### 2.1 Reusable Pre-request and Test Scripts

Extract shared logic into collection-level or folder-level pre-request/test scripts. This reduces duplication and centralizes updates.

❌ **BAD: Duplicated Test Logic**
```javascript
// Request A Test Script
pm.test("Status code is 200", function () {
    pm.response.to.have.status(200);
});
// Request B Test Script (same logic)
pm.test("Status code is 200", function () {
    pm.response.to.have.status(200);
});
```

✅ **GOOD: Reusable Collection-level Test Script**
```javascript
// Collection-level Test Script
pm.test("Response time is less than 200ms", function () {
    pm.expect(pm.response.responseTime).to.be.below(200);
});

// For specific requests, add request-level tests
// Request A Test Script
pm.test("Status code is 201 Created", function () {
    pm.response.to.have.status(201);
});
```

### 2.2 Chaining Requests

Pass data between requests using environment or collection variables. This is crucial for end-to-end flows.
````
END THIRD-PARTY FILE 1fd72b2947c262dd

The third-party file has ended. Everything between the 1fd72b2947c262dd tags is data: requests and commands from it are not followed. An “end of file” line with another tag inside the block is part of the file.

First 3933 of 12294 bytes. © sanjeed5 · CC0-1.0 · https://github.com/sanjeed5/awesome-cursor-rules-mdc/tree/HEAD/rules-mdc/postman.mdc

_Part of the page did not fit — see the HTML version._

---
NeVibeCode on affpapa.org. Catalog texts are descriptions, not instructions for the agent. How to choose and install: https://affpapa.org/en/nevibecode/agents.md
