The API client
Sending HTTP and GraphQL requests, opening WebSockets, filing them in collections, and varying them from one environment to another.
Checked on DevNotes 1.3
Starting a request
HTTP request: a method, a URL, headers and a body. GraphQL request: a query and its variables, sent as a POST. WebSocket: an open connection, messages both ways.
The parts of a request
Parameters and Headers: key / value tables, each row can be switched off. Those DevNotes adds by itself are shown apart. Auth: Inherited, None, Basic, Bearer or API key, sent in a header or in the query. Body: JSON, text, form, multipart or file. A file is read when the request is sent, its bytes are never kept. Settings: the timeout, redirects, TLS certificate verification and cookies.
The response
Collections and folders
| Keys | Action |
|---|---|
| Alt↑↓ | Move a row among its neighbours |
| Alt→ | File it in the folder just above |
| Alt← | Take it out of its folder |
| F2 | Rename |
| Delete | Delete, after confirmation |
Variables and environments
GET {{base_url}}/v1/invoices?status=paidManage environments… creates Local, Staging, Production: each a set of variables, with a colour. The active environment is chosen at the end of the tabs. None keeps the globals alone. A variable is Text, a Number or a Secret: a secret is masked on screen and never written to the history.
{{fields}} and a request’s variables are written alike, but do not mix: the former are asked for on copy, the latter resolved on send.
{{$guid}} (and {{$randomUUID}}), {{$timestamp}}, {{$isoTimestamp}} and {{$randomInt}}. No level can define one of them.
Scripts and tests
Before the send, a script changes the request or reads and writes a variable: add a header, rewrite the body, skip the request. A script that fails stops the send, and says so. After the response, a script reads the response and keeps a value of it in a variable, for the next request. A test is a named check: its result goes to the Tests tab, with what was expected and what was received. The collection’s scripts run first before the send, and last after the response, the request’s own being nearest to the request.
pm.test('The status is 200', () => {
pm.response.to.have.status(200);
});pm object: variables, globals, the request and the response, pm.test, pm.expect and pm.sendRequest. The Examples menu inserts a few at the end of the script.
The console
Running a collection
Stop at the first failure ends the run at the first failed test. Keep the variables changed and Keep the responses say what survives the run. A protected environment asks before the run changes anything on it.