Set auth, variables and scripts once, on a collection or folder

A collection with fifty requests, each with its own copy of the Authorization header, works until the auth scheme changes. Then it's fifty edits, and the one you miss fails in CI a week later.

Collections and folders can hold the settings their requests share.

Auth

Set auth on the collection (or a folder) once: bearer token, basic, API key in a header or the query, OAuth 2.0, AWS Signature and the other types. New requests inherit it. A request uses its own auth only when you pick one on it.

A common layout:

Output
๐Ÿ“ Orders API                      auth: Bearer {{token}}
  ๐Ÿ“‚ Public                        auth: No auth
    GET Health
    GET Product catalog
  ๐Ÿ“‚ Admin                         auth: Bearer {{adminToken}}
    POST Refund order
  POST Create order                (inherits the collection's)

Each request inherits from the nearest folder that sets auth. Changing the admin token variable or the auth type is one edit.

Variables

Collection and folder variables are defaults for the requests inside:

WhereVariableValue
CollectionapiVersionv2
Folder LegacyapiVersionv1

{{apiVersion}} is v1 inside Legacy and v2 everywhere else. The selected environment overrides both, and the request's Variables panel shows which one won.

Keep environment-specific values (hosts, tokens) in environments, and structural values (versions, paths, page sizes) on the collection or folders.

Scripts

A collection or folder has pre-request and post-response scripts too. For the same phase, they run outside in:

  1. the collection's script;
  2. each folder's, from the top down;
  3. the request's own.

Good candidates for a collection script:

JavaScript
// Pre-request: a request id on every call, for tracing
pm.request.headers.set('X-Request-Id', require('uuid').v4());
JavaScript
// Post-response: remember the last request id for bug reports
pm.environment.set('lastRequestId', pm.response.headers.get('X-Request-Id') || '');

Signing every request with HMAC belongs here too; see signing requests with HMAC.

Because Requestarium has no shared headers, a collection pre-request script is also the way to add a header to every request.

Assertions

A collection's and a folder's Tests tab hold assertions every request inside inherits, such as "status is less than 500". See assertions on a collection or folder.

Timeouts

A request's timeout is its own if set, else the nearest folder's, else the collection's, else 30 seconds. Put a long timeout on a Reports folder, and leave the rest at the collection's default.

Exports keep it

Collection and folder auth, variables and scripts are part of every Requestarium JSON export, also when you export a single folder or request. Formats without a place for them get the effective values instead: Insomnia, HAR, .http and cURL write the inherited auth onto each request. See exporting to other formats.

Overriding, when you have to

A request can always set its own auth, variables or timeout. Before you override, ask whether the request belongs in a different folder. A folder whose requests all override its auth is a folder with the wrong auth.