postman

📁 g1joshi/agent-skills 📅 3 days ago
2
总安装量
2
周安装量
#72298
全站排名
安装命令
npx skills add https://github.com/g1joshi/agent-skills --skill postman

Agent 安装分布

mcpjam 2
claude-code 2
replit 2
junie 2
zencoder 2

Skill 文档

Postman

API development and testing platform.

When to Use

  • Testing REST APIs
  • API documentation
  • Automated testing
  • Team API collaboration

Quick Start

// GET request with params
// URL: {{baseUrl}}/users?status=active

// POST request body (JSON)
{
  "name": "John Doe",
  "email": "john@example.com"
}

Core Concepts

Environment Variables

// Environments: Development, Staging, Production

// Variables
{
  {
    baseUrl;
  }
} // https://api.example.com
{
  {
    apiKey;
  }
} // your-api-key
{
  {
    userId;
  }
} // 123

// Pre-request Script
pm.environment.set("timestamp", Date.now());

Tests & Assertions

// Response status
pm.test("Status is 200", () => {
  pm.response.to.have.status(200);
});

// Response JSON
pm.test("User has correct email", () => {
  const json = pm.response.json();
  pm.expect(json.email).to.equal("test@example.com");
});

// Response time
pm.test("Response time < 500ms", () => {
  pm.expect(pm.response.responseTime).to.be.below(500);
});

// Save data for next request
const token = pm.response.json().token;
pm.environment.set("authToken", token);

Common Patterns

Authentication

// Pre-request Script for OAuth
const tokenUrl = pm.environment.get("tokenUrl");
const clientId = pm.environment.get("clientId");
const clientSecret = pm.environment.get("clientSecret");

pm.sendRequest(
  {
    url: tokenUrl,
    method: "POST",
    header: {
      "Content-Type": "application/x-www-form-urlencoded",
    },
    body: {
      mode: "urlencoded",
      urlencoded: [
        { key: "grant_type", value: "client_credentials" },
        { key: "client_id", value: clientId },
        { key: "client_secret", value: clientSecret },
      ],
    },
  },
  (err, res) => {
    pm.environment.set("accessToken", res.json().access_token);
  },
);

Collection Runner

// Run collection with Newman (CLI)
npx newman run collection.json \
  -e environment.json \
  --reporters cli,htmlextra \
  --iteration-count 5

Best Practices

Do:

  • Use environments for different stages
  • Write tests for critical responses
  • Version control collections
  • Use collection variables

Don’t:

  • Hardcode secrets
  • Skip response validation
  • Create duplicate requests
  • Ignore collection organization

Troubleshooting

Issue Cause Solution
Variable not resolved Wrong scope Check environment selection
SSL error Certificate issue Disable SSL verification (dev only)
CORS error Browser restriction Use Postman desktop app

References