@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.
- package/README.md +32 -8
- package/dist/hosts/antigravity.js +47 -0
- package/dist/hosts/copilot.js +60 -0
- package/dist/hosts/index.js +3 -1
- package/mcp.pi.json +2 -2
- package/package.json +1 -1
- package/skills/ai-readiness/SKILL.md +40 -44
- package/skills/api-discovery/SKILL.md +64 -145
- package/skills/api-discovery/reference/orbit.md +17 -5
- package/skills/api-documentation/SKILL.md +41 -46
- package/skills/api-engineer/SKILL.md +78 -23
- package/skills/api-mocking/SKILL.md +117 -163
- package/skills/api-monitoring/SKILL.md +52 -129
- package/skills/api-simulation/SKILL.md +130 -178
- package/skills/api-simulation/reference/sim_yaml_schema.md +41 -103
- package/skills/api-testing/SKILL.md +48 -95
- package/skills/bootstrap/SKILL.md +123 -224
- package/skills/ci-integration/SKILL.md +53 -113
- package/skills/collection-schema-v3/SKILL.md +43 -204
- package/skills/collection-schema-v3/reference/http.md +150 -0
- package/skills/datasets/SKILL.md +89 -315
- package/skills/datasets/reference/spreadsheets.md +25 -0
- package/skills/flows/SKILL.md +57 -206
- package/skills/flows/reference/flow_cli_flags.md +3 -2
- package/skills/performance-testing/SKILL.md +46 -62
- package/skills/performance-testing/references/jmeter-import/README.md +113 -0
- package/skills/performance-testing/references/jmeter-import/import-report.md +52 -0
- package/skills/performance-testing/references/jmeter-import/mapping-table.md +97 -0
- package/skills/performance-testing/references/jmeter-import/postman-perf-capabilities.md +56 -0
- package/skills/performance-testing/references/jmeter-import/script-translation.md +98 -0
- package/skills/performance-testing/references/jmeter-import/scripts/groovy_to_js.py +83 -0
- package/skills/performance-testing/references/jmeter-import/scripts/jmx_to_postman.py +1433 -0
- package/skills/postman-mcp-server/SKILL.md +53 -59
- package/skills/postman-mcp-server/references/docs.md +0 -1
- package/skills/postman-mcp-server/references/learn.md +10 -9
- package/skills/postman-mcp-server/references/mock.md +0 -1
- package/skills/postman-mcp-server/references/search.md +0 -1
- package/skills/postman-mcp-server/references/security.md +0 -1
- package/skills/postman-mcp-server/references/setup.md +0 -1
- package/skills/postman-mcp-server/references/sync.md +0 -1
- package/skills/postman-mcp-server/references/test.md +0 -1
- package/skills/variables/SKILL.md +44 -87
- package/skills/webhook-testing/SKILL.md +103 -0
- package/skills/webhook-testing/reference/forwarding.md +10 -0
- package/skills/webhook-testing/reference/outbound_webhooks.md +25 -0
- package/skills/webhook-testing/reference/webhook_scripts.md +163 -0
|
@@ -1,52 +1,47 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: api-documentation
|
|
3
|
-
description:
|
|
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
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
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:
|
|
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
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
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:
|
|
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
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
`
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
`
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
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.
|