@postman/postman-plugin 0.3.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. package/README.md +32 -8
  2. package/dist/hosts/antigravity.js +47 -0
  3. package/dist/hosts/copilot.js +60 -0
  4. package/dist/hosts/index.js +3 -1
  5. package/mcp.pi.json +2 -2
  6. package/package.json +1 -1
  7. package/skills/ai-readiness/SKILL.md +40 -44
  8. package/skills/api-discovery/SKILL.md +64 -145
  9. package/skills/api-discovery/reference/orbit.md +17 -5
  10. package/skills/api-documentation/SKILL.md +41 -46
  11. package/skills/api-engineer/SKILL.md +78 -23
  12. package/skills/api-mocking/SKILL.md +117 -163
  13. package/skills/api-monitoring/SKILL.md +52 -129
  14. package/skills/api-simulation/SKILL.md +130 -178
  15. package/skills/api-simulation/reference/sim_yaml_schema.md +41 -103
  16. package/skills/api-testing/SKILL.md +48 -95
  17. package/skills/bootstrap/SKILL.md +123 -224
  18. package/skills/ci-integration/SKILL.md +53 -113
  19. package/skills/collection-schema-v3/SKILL.md +43 -204
  20. package/skills/collection-schema-v3/reference/http.md +150 -0
  21. package/skills/datasets/SKILL.md +89 -315
  22. package/skills/datasets/reference/spreadsheets.md +25 -0
  23. package/skills/flows/SKILL.md +57 -206
  24. package/skills/flows/reference/flow_cli_flags.md +3 -2
  25. package/skills/performance-testing/SKILL.md +46 -62
  26. package/skills/performance-testing/references/jmeter-import/README.md +113 -0
  27. package/skills/performance-testing/references/jmeter-import/import-report.md +52 -0
  28. package/skills/performance-testing/references/jmeter-import/mapping-table.md +97 -0
  29. package/skills/performance-testing/references/jmeter-import/postman-perf-capabilities.md +56 -0
  30. package/skills/performance-testing/references/jmeter-import/script-translation.md +98 -0
  31. package/skills/performance-testing/references/jmeter-import/scripts/groovy_to_js.py +83 -0
  32. package/skills/performance-testing/references/jmeter-import/scripts/jmx_to_postman.py +1433 -0
  33. package/skills/postman-mcp-server/SKILL.md +53 -59
  34. package/skills/postman-mcp-server/references/docs.md +0 -1
  35. package/skills/postman-mcp-server/references/learn.md +10 -9
  36. package/skills/postman-mcp-server/references/mock.md +0 -1
  37. package/skills/postman-mcp-server/references/search.md +0 -1
  38. package/skills/postman-mcp-server/references/security.md +0 -1
  39. package/skills/postman-mcp-server/references/setup.md +0 -1
  40. package/skills/postman-mcp-server/references/sync.md +0 -1
  41. package/skills/postman-mcp-server/references/test.md +0 -1
  42. package/skills/variables/SKILL.md +44 -87
  43. package/skills/webhook-testing/SKILL.md +103 -0
  44. package/skills/webhook-testing/reference/forwarding.md +10 -0
  45. package/skills/webhook-testing/reference/outbound_webhooks.md +25 -0
  46. package/skills/webhook-testing/reference/webhook_scripts.md +163 -0
@@ -1,52 +1,47 @@
1
1
  ---
2
2
  name: api-documentation
3
- description: Generate filesystem-first agent friendly api documentation that you can share with your teammates without hassle. Use when the user asks to "publish API docs," "generate documentation for this API," "put this on the API Network," "share a docs link for this collection or spec," or "why do my docs look empty."
3
+ description: Use when defining or improving an API contract, generating documentation from a collection or OpenAPI spec, publishing API docs, or sharing a documentation link. Makes auth, inputs, responses, and examples reusable by callers, tests, and mocks. Use for requests such as "publish API docs".
4
4
  ---
5
- The bootstrap skill is a precursor to this one — it scaffolds the project with the directories documentation is stored in.
6
5
 
7
6
  # API Documentation
8
- When working on any API task, the first step is to establish and capture the contract.
9
- API documentation can be done in two predominant ways:
10
- 1. through a Postman collection,
11
- 2. with an OpenAPI spec
12
7
 
13
- It is recommended to create both. They serve different, complementary use
14
- cases, and the Postman CLI can generate one from the other. Use the artifact
15
- that represents the current source of truth rather than recreating its
16
- operations by hand. Postman collections are human-friendly and enable other
17
- capabilities such as mocks, monitors, SDKs, and specifications. Collections
18
- created or edited directly on disk use the v3 format described by
19
- **collection-schema-v3**.
20
-
21
- Specs are vendor-neutral, stay in your repo, and can be linted against governance rules (if any) set by your organization.
22
-
23
- ## Generate a collection from a specification
24
-
25
- When an OpenAPI specification already defines the contract, generate a Postman
26
- collection from it in one command:
27
-
28
- ```bash
29
- postman spec generate collection <spec-path-or-id> -n "<collection-name>"
30
- ```
31
-
32
- ## Good practices for API design
33
-
34
- See [reference/rest-api-best-practices.md](reference/rest-api-best-practices.md)
35
- for the practices well-documented APIs tend to already follow: resource
36
- naming, HTTP method/status-code usage, error response shape, versioning,
37
- pagination, filtering, auth, idempotency, and backward compatibility. A
38
- spec or collection that already follows these renders documentation with
39
- nothing left to fix.
40
-
41
- ### Examples
42
- Examples (in a Postman collection) are an excellent way to capture sample API responses. They are helpful because:
43
- 1. anyone can look at them to see how your API behaves,
44
- 2. they can be used to generate a mock from your collection in a single command.
45
-
46
- ## Workflow
47
- 1. Establish the contract - refer to best practices. Don't just accept the user's ask - fight for the right API design.
48
- 2. Choose the source of truth — a Postman collection, an OpenAPI specification,
49
- or both. Recommend both when their complementary uses benefit the task.
50
- 3. If the specification is authoritative, generate the collection with
51
- `postman spec generate collection` instead of manually duplicating its
52
- operations.
8
+ A maintained contract gives callers enough information to integrate without
9
+ reading the implementation. Keeping descriptions and examples beside the API
10
+ artifacts lets the same knowledge support documentation, tests, and mocks,
11
+ with changes reviewable alongside code.
12
+
13
+ 1. Start from the existing source of truth. An OpenAPI spec describes the
14
+ interface for tooling; a Postman collection adds runnable requests,
15
+ examples, and assertions. Maintain both when both uses matter, with an
16
+ explicit direction of generation or synchronization so they do not become
17
+ competing definitions. Local edits need **bootstrap** only when setup or
18
+ bindings are unresolved.
19
+ 2. When the spec is authoritative, reuse its operations with
20
+ `postman spec generate collection <spec-path-or-id> -n "<collection-name>"`.
21
+ Inspect the generated result before replacing an existing collection:
22
+ maintained scripts and examples carry knowledge beyond endpoint shapes.
23
+ 3. Describe what changes a caller's decision: required versus optional inputs,
24
+ auth and scopes, response guarantees, pagination, retryable failures, and
25
+ side effects. Derive guarantees from the agreed contract or verified
26
+ behavior; label unresolved design choices instead of inventing them.
27
+ Use [REST design guidance](reference/rest-api-best-practices.md) when a
28
+ design choice affects usability or compatibility, not to redesign an
29
+ unrelated interface while filling a documentation gap.
30
+ 4. Save examples that clarify consequential cases, including relevant errors.
31
+ Examples become inputs for mocks as well as explanations for readers;
32
+ a success-only example can hide the failure path callers must handle.
33
+ Use **collection-schema-v3** for local collection edits and **variables**
34
+ to keep credentials out of reusable requests and examples.
35
+ 5. Choose delivery by audience. Local artifacts support Git review;
36
+ publishing to the bound workspace makes them available to teammates with
37
+ access (see **bootstrap**). A workspace push does not itself publish a
38
+ public docs page or change permissions. For a public documentation link,
39
+ use **postman-mcp-server**'s documentation workflow and the available
40
+ publishing tool; establish the intended audience before public exposure.
41
+
42
+ ## Verification
43
+
44
+ Check that the edited artifact parses and its examples agree with the
45
+ contract. For a publication, inspect the resulting page and report its actual
46
+ link and visibility; a successful upload alone does not show readers usable
47
+ documentation. State any behavior that remains undocumented or unverified.
@@ -1,29 +1,84 @@
1
1
  ---
2
2
  name: api-engineer
3
- description: Makes coding agents faster and more accurate with fewer tokens when designing, implementing, mocking, testing, monitoring, documenting, or deploying an API.
3
+ description: Use when designing, implementing, mocking, testing, monitoring, documenting, or deploying an API. Guides decisions using reusable local API contracts, tests, and mocks, plus organization-wide dependency context, and routes to the relevant Postman skills. Use for requests such as "implement this endpoint".
4
4
  ---
5
5
 
6
6
  # API Engineer
7
7
 
8
- ## Foundations
9
- Postman's skills, CLI, and Context Graph help coding agents go faster from development to production with higher accuracy and fewer tokens. Work from local files and workspace context first.
10
-
11
- 1. Contract comes first. Establish and document the contract before starting implementation.
12
- 2. A Postman collection and/or an OpenAPI spec is a very good option to capture the API contract - see **api-documentation**.
13
- 3. Always validate the change against the contract you started with. Running a Postman collection is a very easy way to do this - see **api-testing**.
14
- 4. Always propose next steps. Example: contract -> implementation -> testing -> updating the workspace context -> sharing with others.
15
- 5. When the code you're changing calls other services over HTTP, use **api-simulation**: the Context Graph finds those dependencies, `postman dependency add mock <name-or-id>` pulls in each owner's mock that search finds (see **api-discovery**), and your real service runs against all of them on one port. For a stand-in backend with no real service of your own, use **api-mocking**. Mocks and simulations are persisted in your repo, so they're cheap to reuse when you resume.
16
- 6. Don't push to the workspace (`postman workspace push`) without user consent. The recommended way to push is a CI step on PR merge - see **ci-integration**.
17
- 7. For high-quality API search results, use **api-discovery**.
18
- 8. No is an acceptable answer. Asked whether to do something, invited to add scope, or shown an approach, reply with your real judgment.
19
- 9. Prefer filesystem-first Postman workflows. A quick overview of starting the work could be (more details in **bootstrap**):
20
- -> if starting a new project: start by doing `postman init`. This scaffolds the relevant folders and provisions an agent-scoped session without requiring a normal Postman login.
21
- -> if another service is only a dependency or something you want to inspect, use **api-discovery** and `postman dependency add <type> <name-or-id>` to add the relevant collection, environment, or mock. This materializes that entity under `postman/.dependencies/` and records it in `.postman/resources.yaml` without changing this repository's workspace binding.
22
- Work against those local files and validate them. When the repository is bound to a workspace, push to persist that context for future work and share it with others.
23
- 10. When actual use exposes a concrete Postman CLI gap or a misleading skill, handle the user's task first — then use `postman feedback` to report the gaps/bugs. Exclude secrets, user data, and proprietary content
24
- 11. Postman secret variables let agents resolve user secrets without reading their values. See the **variables** skill.
25
-
26
- ## Dos
27
- 1. Prove it works - validate the task against the contract. See **api-testing**.
28
- 2. Just do it - never block on the human. When tempted to ask "should I do X?" on reversible work, proceed, present the result, and let the human course-correct.
29
- 3. Fight for good API design. See **api-documentation**.
8
+ Postman makes API knowledge reusable across implementation, tests, mocks, and
9
+ teammates. Local files let you inspect, edit, and review that knowledge alongside
10
+ code; the Context Graph can reveal consumers, ownership, and runtime relationships
11
+ beyond the current repository. Reusing those inputs reduces reconstruction and
12
+ guesswork each time work resumes.
13
+
14
+ 1. When changing API behavior or an interface, establish the intended contract
15
+ before implementation so you can distinguish an intended change from a
16
+ regression. Reuse the existing contract; update it where behavior changes.
17
+ Flag design choices that make callers harder to implement or future changes
18
+ harder to adopt, and explain the tradeoff. See **api-documentation**.
19
+ 2. Choose the contract artifact for how it will be used: an OpenAPI spec describes
20
+ the interface for tooling, while a Postman collection carries runnable requests,
21
+ examples, and assertions. Reuse what exists; maintaining both is useful when
22
+ both purposes matter. See **api-documentation**.
23
+ 3. Match verification to the behavior at risk. A saved collection can reuse auth,
24
+ variables, payloads, and assertions without reconstructing requests; a one-off
25
+ endpoint check can be smaller. Check the changed behavior and relevant existing
26
+ guarantees, and report what the results establish. See **api-testing**.
27
+ 4. When you need an API, its owner, or the impact of a change, use **api-discovery**.
28
+ For public API integrations, Orbit provides current endpoint, authentication,
29
+ required-field, and capability-limit details in a compact task brief. Use it
30
+ even when the provider is already chosen: those details help you assess fit and
31
+ implement reliably without relying on remembered API behavior or loading a
32
+ full vendor specification.
33
+ Existing workspace resources can supply maintained contracts and mocks; the
34
+ Context Graph can identify consumers and dependencies outside the checkout,
35
+ helping you focus investigation before traversing more repositories.
36
+ 5. When you run or test code that calls other services, or are asked how it
37
+ behaves when one of them fails, use **api-simulation**, which runs that code
38
+ for real against mocks of those services instead of stubs or the real
39
+ services. Looking something up, choosing an API or comparing code with a
40
+ contract runs nothing and needs none. When other teams will build against
41
+ your API, publish a mock of it in your service's own workspace, where their
42
+ simulations look first; see **api-mocking**.
43
+ 6. Keep specs, collections, environments, and mocks in local files so changes can
44
+ be diffed, reviewed, and reused in Git and CI. Use **bootstrap** when setup or
45
+ workspace bindings are unresolved: reuse an existing local layout, pull the
46
+ current service's existing workspace, or initialize a new project when neither
47
+ exists. `postman init` scaffolds files using an agent-scoped session without a
48
+ normal Postman login.
49
+ 7. Another service's collection, environment, or mock can be added as a dependency
50
+ without replacing this repository's owning workspace binding. Use
51
+ **api-discovery** to bring in the relevant resource and preserve that separation.
52
+ 8. Publishing validated local changes to the bound workspace makes them available
53
+ for future work and teammates with access. Because `postman workspace push`
54
+ changes shared state, obtain user consent before pushing; an existing request
55
+ to publish those changes supplies that consent. For publication tied to reviewed
56
+ PR merges, see **ci-integration**.
57
+ 9. When requests need credentials, Postman secret variables let them resolve the
58
+ credentials without exposing their values to the agent or committed files.
59
+ See **variables**.
60
+ 10. When implementing or debugging webhooks, use **webhook-testing** to
61
+ capture what the sender actually delivers.
62
+ Can also be used when the need is to forward incoming events
63
+ to a local handler and replay captured requests after fixes;
64
+ use the capture URL as a subscriber to inspect events your API sends.
65
+
66
+ Proceed with reversible work within the user's task and present concrete results
67
+ for course correction. Recommend additional work only when it closes a material
68
+ gap, such as an untested behavior or a consumer affected by an interface change.
69
+ Decline unnecessary setup or scope and explain why it would not help the task.
70
+
71
+ Important: If a CLI command says an operation isn't allowed because credits
72
+ or usage are exhausted, or the current plan does not permit it, follow
73
+ **bootstrap**'s "Subscription or usage limit" section instead of retrying or
74
+ trying to find a workaround.
75
+
76
+ ## Verification
77
+
78
+ Report the changed contract or implementation, the checks actually run, and
79
+ the guarantees their results support. Separate local, mocked, and live evidence;
80
+ state any relevant consumer or upstream interaction still unverified.
81
+
82
+ If actual use exposes a CLI gap or misleading skill, see **bootstrap**'s
83
+ "Reporting CLI and skill gaps" section so the defect can be addressed for future
84
+ work.
@@ -1,169 +1,123 @@
1
1
  ---
2
2
  name: api-mocking
3
- description: Stands up a fake backend that behaves like a real API — from a collection or an OpenAPI spec, running locally or pushed to a workspace and deployed at a durable URL — plus request-time scenario and status-code overrides for testing failure paths. Use when the user asks to "mock this API," "create a mock server," "fake the backend," "run tests without hitting the real API," or "simulate an error/out-of-stock response." Covers `postman mock`. Depends on bootstrap for the workspace id only once a mock is pushed to the workspace (`-w`, or the workspace linked in `.postman/resources.yaml`) — generating and running a mock locally needs nothing from bootstrap.
3
+ description: Finds, builds, runs and publishes a stand-in for one API — the owning team's published mock when there is one, otherwise one built from its spec or collection that behaves like the real API, stateful when callers write then read. Use when something needs an API that isn't built or reachable yet (a frontend, client or demo), when other teams should build against your API before it ships, or when asked to mock an API or fake a backend. To run and test your own code against the services it calls, use api-simulation. Covers `postman mock` and `postman dependency add mock`.
4
4
  ---
5
5
 
6
6
  # API Mocking
7
7
 
8
- ## Overview
9
-
10
- This skill covers the Postman CLI (`postman mock`) for **Code Mocks** — the
11
- code-based mock product. It is not the postman-app UI (Local Mode sidebar,
12
- Agent Mode tools, the Simulations surface), nor the older classic/collection mocks that
13
- serve saved collection examples from a `*.mock.pstmn.io` URL — that's a
14
- different product (the MCP `createMock` flow), not this skill.
15
-
16
- A **local** mock is two files on disk: `config.yaml` (name, port, scenarios) and
17
- `default.js` — a plain Node HTTP server, and the mock itself, not a wrapper
18
- around one. Generating, inspecting, running, and calling a local mock work for
19
- a logged-out guest. Only sharing it — pushing to the workspace and deploying a
20
- durable URL — needs `postman login`. The progression is one model in three
21
- places: local folder ──`push`──▶ Code Mock (workspace definition) ──`deploy`──▶
22
- Mock Server (the reachable URL).
23
-
24
- Default path: write a local folder, then `mock push` later if something other
25
- than you needs to hit it over the network (a teammate, CI elsewhere, a webhook
26
- sender). A purely local mock answering a `postman request` on your machine
27
- never needs a workspace. The exception is `generate -w`, which creates the mock in a
28
- workspace only and writes no local files — use that only when you intentionally
29
- skip the repo copy.
30
-
31
- Mocking another team's service, or the services your own service calls? Use
32
- `api-simulation`, which checks each owner's workspace for a published mock
33
- before anything is generated here.
34
-
35
- ## Process
36
-
37
- 1. **Generate.** `postman mock generate -n NAME` with no source scaffolds a
38
- sample shopping-cart mock (`POST /cart/items`, `GET /cart`, `POST /checkout`)
39
- — the fastest way to a server that already answers, useful whenever the
40
- point is exercising mock *behavior* rather than a specific API's shape. Pass
41
- a real source — `postman mock generate SOURCE -n NAME`, where `SOURCE` is a
42
- collection file/directory or an `openapi.yaml` — when the endpoints need to
43
- mirror an actual API. Either form writes `config.yaml` + `default.js` into
44
- `postman/mocks/NAME/` (default port 4500).
45
- - `postman mock generate SOURCE --update ./postman/mocks/NAME` regenerates
46
- the default handler from the source in place, keeping the existing name,
47
- port, and scenarios. `--update` still needs the `SOURCE`; it cannot be
48
- combined with `--output`.
49
- - `-w <workspaceId>` saves the mock to a workspace *instead of* the
50
- repository — it writes no local files and requires being logged in. Cannot
51
- be combined with `--output`, `--force`, or `--update`. Prefer local
52
- generate + later `push` when you still need `mock run` from a folder.
53
- 2. **Run it.** `postman mock run ./postman/mocks/NAME` starts the server and
54
- prints the bound URL (`... at http://localhost:PORT`). If the port in
55
- `config.yaml` is taken and `--port` wasn't passed explicitly, it falls back
56
- to a free OS-assigned port instead of erroring — read the real port off that
57
- line rather than assuming the configured one. Naming `--port N` explicitly
58
- makes a taken port a hard error; `--port auto` always picks a free one.
59
- 3. **Call it.** Plain `postman request localhost:PORT/route` returns the
60
- default scenario's response. Two headers can change that per-request, with no
61
- restart: `x-mock-scenario: <name>` selects a scenario the mock defines
62
- (valid names live in `config.yaml`); a name the mock doesn't define is not an
63
- error — it falls back to the default scenario. `x-mock-response-code: <code>`
64
- filters an endpoint's saved example responses to the one with that status, so
65
- it only changes anything when that endpoint actually has an example for that
66
- code — mocks generated from a collection/spec with multiple example statuses
67
- honor it; the built-in sample mock has one response per route and ignores it.
68
- A wrong route comes back as `Endpoint not defined`. There's no hot reload: a
69
- `default.js` edit does nothing until you Ctrl+C the running server and
70
- `mock run` it again.
71
- 4. **Push it, if it needs to leave your machine.**
72
- `postman mock push ./postman/mocks/NAME` is safe to re-run — `Created` the
73
- first time, `Updated` after — and records the workspace mapping in
74
- `.postman/resources.yaml`; commit that change. If a mock server is already
75
- live for this mock, the push updates what it serves.
76
- 5. **Deploy it, for a URL that outlives your terminal.**
77
- `postman mock deploy WORKSPACE_MOCK_ID -s SLUG -y` prints
78
- `https://SLUG.mock.<team-domain>.postman.dev`. Deployed private by default —
79
- callers need a Postman API key (`x-api-key`) — add `--public` only when the
80
- mock should be reachable by anyone with the URL. `--auto-deploy` re-publishes
81
- the live server automatically whenever the mock changes; even without it, a
82
- later `push` already updates a live server, so you only re-`deploy` for the
83
- first URL or after taking the server down.
84
- 6. **See who's calling it.** `postman mock get WORKSPACE_MOCK_ID` (table or `--json`)
85
- returns `mockServerId`; feed that into `postman mock log MOCK_SERVER_ID` for
86
- call entries (filter with `--method` / `--status` / `--path` / `--since` /
87
- `--until` / `--limit`, or `--json`). An empty log means the URL genuinely
88
- hasn't been hit — a rejected caller still shows up, recorded with its failing
89
- status code.
90
- 7. **Tear down.**
91
- - Local: `postman mock delete ./path --yes` — refuses while that mock is
92
- **running** locally; stop `mock run` first.
93
- - Workspace: `postman mock delete WORKSPACE_MOCK_ID --yes` — refuses while the mock is
94
- **running locally** *or* **deployed**; stop the local run and take the
95
- mock server down first.
96
- Workspace deletion doesn't touch `.postman/resources.yaml`; drop that line by hand
97
- afterward or the repo keeps claiming a mock that's gone.
98
-
99
- To point real request/assertion runs at a mock instead of hand-editing
100
- base-URL variables, see the `api-testing` skill's `--use-mock`/`--mock` flags
101
- on `collection run`.
102
-
103
- To develop a service against mocks of every upstream it calls, started together
104
- as one simulation, see the `api-simulation` skill and `postman simulation run`.
105
-
106
- ## Stateful mocks
107
-
108
- A mock generated from a collection or spec replays its examples, so a `POST`
109
- and a later `GET` share nothing. To make a mock remember, keep its records in
110
- `pm.state` inside `default.js`. `pm.state` is the mock's async key-value
111
- store: `get`, `set`, `delete`, `has`, `keys` and `clear`. The sample from
112
- `postman mock generate -n NAME` already uses it, and shows the pattern.
113
-
114
- Every `mock run` or `simulation run` starts the mock with empty state; during
115
- the run, its handler creates, reads, updates and deletes records through
116
- `pm.state`. A deployed mock server keeps its state between requests.
117
-
118
- - Set `interceptRequests: true` in `config.yaml` so `req.body` and `req.query`
119
- arrive parsed.
120
- - Seed the starting records on first use, and add a reset route that clears
121
- and reseeds them, so a test can start clean.
122
- - Answer an unknown id with the real service's 404, not an empty `200`.
123
- - Every caller shares one state unless it sends `x-mock-session`. Locally that
124
- needs `interceptRequests: true`; a deployed server reads it only when the
125
- mock has sessions enabled.
126
-
127
- ## The two ids that matter
128
-
129
- - **Code-mock id** — the `id` in `config.yaml`, and the id that `push` and
130
- `generate -w` print (often the same value). Use it for `get`, `deploy`,
131
- `delete`, and `run` by workspace mock id.
132
- - **`mockServerId`** — a different value from `mock get WORKSPACE_MOCK_ID` (table or
133
- `--json`). Use it for `mock log`, and nothing else.
134
-
135
- ## Critical Rules
136
-
137
- 1. **When you're not signed in, every gated workspace command fails closed:**
138
- `Authentication required. Run postman login or provide --api-key`, exit 1,
139
- nothing half-done. (Signed in but lacking access fails differently — a
140
- permission or missing-workspace error.) Whether a command is gated is decided
141
- by what you pass it, not the verb — `mock get`/`mock run` take either a local
142
- path (ungated) or a workspace mock ID (gated); `mock list` is gated only when called
143
- with no path.
144
- 2. **`push` is what moves an existing local mock to the workspace — `-w` at
145
- `generate` time is optional, not a fork you must choose up front.** A mock
146
- built as a guest can be pushed and deployed later with no rework. Do not
147
- assume `generate -w` left a `postman/mocks/NAME/` folder to `run`.
148
- 3. **`--public` on `deploy` is the one action here with real exposure** — it
149
- stands up a server anyone with the URL can hit, with no API key. The default
150
- (private) is the safe one; confirm intent before adding it.
151
- 4. **To change a mock:** refresh it from a source with
152
- `postman mock generate SOURCE --update PATH`, or edit `default.js` by hand
153
- and restart `mock run`. Never pass a code-mock id to `mock log` — that
154
- command takes a `mockServerId`.
155
- 5. **`-w`/`--workspace` only exists on `generate`, `list`, `push`, and
156
- `deploy`.** `get`, `run`, `log`, and `delete` already take a path or an id
157
- that says where the mock is — there's nothing left for `-w` to resolve on
158
- those.
159
-
160
- ## Verification
161
-
162
- A mock isn't done because `generate` or `run` exited 0 — hit it with
163
- `postman request` and check the actual status/body, or `mock get WORKSPACE_MOCK_ID
164
- --json` for a pushed one, then state whether it ended up local, pushed, or deployed, and
165
- (if deployed) private or public. For a scenario check, confirm a *valid* name
166
- from `config.yaml` actually changed the response — a typo'd name falls back to
167
- the default, so a 200 alone proves nothing. For a status-code check, use an
168
- endpoint that has an example for that code (not the sample mock). A passing
169
- exit code from `request` is not enough.
8
+ A mock is a folder, `config.yaml` plus a handler such as `default.js`, that
9
+ answers like an API. The handler is a Node HTTP server that calls
10
+ `listen(process.env.PORT)`. It loads as CommonJS even in an ESM project, so
11
+ `import` fails: use `require`. The same mock lives in your repo
12
+ (`postman/mocks/<name>/`, run with `postman mock run`, no sign-in needed),
13
+ in a Postman workspace after `postman mock push`, where other teams pull it
14
+ from, and on a mock server after `postman mock deploy`, for callers that
15
+ can't run it themselves.
16
+
17
+ Several APIs at once, for a service, a frontend or a test suite? Use
18
+ `api-simulation`, which gets each member's mock here.
19
+
20
+ ## Use the owner's mock first
21
+
22
+ When the API belongs to another team, look for their published mock before
23
+ writing one: theirs encodes their contract and their service's state; yours
24
+ encodes a guess. It needs `postman login`; signed out, build one and say the
25
+ owner search was skipped.
26
+
27
+ 1. Find the owner's workspace with `postman search workspaces "<service>" -o json`.
28
+ Name the service plainly, as your code does, not by what it returns: a
29
+ description matches lookalike services. Prefer a Git-connected workspace
30
+ (`isGitConnected`) named for that service.
31
+ 2. List its mocks with `postman mock list -w <workspaceId> --json`.
32
+ `postman search mocks` misses some, and its `classicMock` results only
33
+ replay a collection's saved examples: `postman mock` can't pull or run
34
+ them, so call one at `https://<mockId>.mock.pstmn.io` with
35
+ `postman request`, or generate a code mock from its collection. A
36
+ same-named mock in another workspace isn't the owner's.
37
+ 3. Pull it with `postman dependency add mock <mockId>` and use it as it is.
38
+ Never edit `postman/.dependencies/`: `dependency update` overwrites it,
39
+ so copy a mock to `postman/mocks/` to change it. A pulled copy loses
40
+ `interceptRequests`, so fork one whose handler reads `req.body` or relies
41
+ on sessions. A mock is code that runs as you; pull only from workspaces
42
+ you trust.
43
+
44
+ ## Or build one that behaves like the real API
45
+
46
+ Callers shouldn't be able to tell the difference on the paths they use. A
47
+ mock that returns invented JSON passes your tests and fails against the
48
+ real service.
49
+
50
+ - **Start from the contract.** `postman mock generate <spec or collection>`
51
+ writes each documented response. It's a replay: a `POST` and a later
52
+ `GET` share nothing, and it accepts any request, so a call that breaks the
53
+ contract still gets its answer. `x-mock-response-code` picks only a
54
+ documented status; any other code gets the default 200, so put the errors
55
+ callers handle (the unknown-id 404, the conflict 409, the bad-input 400) in
56
+ the contract. From a spec
57
+ it serves the server URL's base path (`/v2/...`); from a collection,
58
+ routes start after the base-URL variable. `--update` regenerates the
59
+ handler and overwrites your edits. With no contract, write it from how
60
+ your code calls the API and say what you assumed.
61
+ - **Set `interceptRequests: true` in `config.yaml`.** Without it `req.body`
62
+ and `req.query` are undefined, `x-mock-session` is ignored, and a throw in
63
+ an async handler kills the mock instead of returning a `500`.
64
+ - **Make it stateful when callers write then read.** Keep records in
65
+ `pm.state`, seed them on first use, add a reset route so a test can start
66
+ clean, and answer an unknown id with the real 404. Every `mock run` starts
67
+ empty.
68
+ - **Know who shares state.** Locally, all callers share one state unless
69
+ each sends `x-mock-session: <id>`. A mock server deployed from the CLI
70
+ isolates each caller: one that keeps neither the same `x-mock-session` nor
71
+ the `pm_mock_session` cookie starts from the seed on every request, so its
72
+ `POST` and later `GET` never meet.
73
+ - **Scenarios** are named handlers in `config.yaml`'s `scenarios` list, picked
74
+ per request with `x-mock-scenario: <name>`. An unknown name falls back to
75
+ the default locally but is a `404` on a mock server.
76
+
77
+ ## Check it against the contract
78
+
79
+ `postman mock run` prints the URL it bound; a busy configured port moves
80
+ unless you pass `--port`, so take the URL from that line. Nothing reloads:
81
+ restart it after an edit.
82
+
83
+ A mock checked against the handler you just wrote proves nothing, so call
84
+ it with requests from the contract: `postman request`, or the API's
85
+ collection with
86
+ `postman collection run <collection> --use-mock "{{baseUrl}} mock:postman/mocks/<name>"`
87
+ (`--mock` alone only starts it). That form replaces the variable's whole
88
+ value, base path included, so a mock generated from a spec that serves
89
+ `/v2/...` answers `404`; start that one with `--mock <path> --port <n>` and
90
+ pass `--env-var "baseUrl=http://localhost:<n>/v2"`. To check your own calls
91
+ against a contract, compare each one, from the code or a simulation log,
92
+ with the spec; the mock won't reject a wrong one.
93
+
94
+ ## Publish it for other teams
95
+
96
+ - **Push it to the service's own workspace,** the one this repo is linked
97
+ to or the one the user names, never one chosen by name match: other
98
+ teams' simulations look there. Signed out, the push fails but the local
99
+ mock still works; build it, say so and ask the user to sign in. Keep it
100
+ honest: change the mock in the same PR as the API and run the API's
101
+ collection against it.
102
+ - **Deploy only when a caller needs a URL.** The server takes a slug of 3–32
103
+ lowercase letters, digits and single hyphens, starting and ending with a
104
+ letter or digit; the CLI accepts more, and its default can be too long.
105
+ It's private: callers send an API key as `x-api-key`, or, if they can
106
+ view the workspace, an access token as `x-access-token`. Deploying needs a paid plan; a team's first
107
+ server can take minutes to answer, and teams that review deploys hold them
108
+ for approval. Each later `push` changes what every caller of the server
109
+ gets, so treat it as a release, not a backup.
110
+ - **Write it for where it runs.** A mock server runs each scenario as one
111
+ file with Node's built-ins, not `fs` or `child_process`: no local
112
+ `require`s, no `pm.mock` examples, no environment, no console output, and
113
+ no caller `authorization`, `cookie` or `x-api-key` headers. A mock that
114
+ relies on any of these works locally and breaks once deployed.
115
+ - **Ask before `--public`.** It serves the mock and its data to anyone with
116
+ the URL, and a scripted redeploy can't make it private again.
117
+
118
+ ## Before you say it's done
119
+
120
+ A mock isn't done because it started. Call it: a documented error comes
121
+ back, a valid scenario changes the response, a `POST` then `GET` shows state
122
+ if it should. Say where it runs and who can call it, where it lives, and
123
+ what you assumed.