>_ RESTERM
v1.18.2

examples Scripts and checks

scripts.http

A RestermScript pre-request block that sets a token, headers and body, then an @assert check.

runs as-is

shell
resterm run --all _examples/scripts.http

Run this from the root of a clone of the Resterm repository.

Editor
# Top-level globals apply to every request below without needing an immediate request line.
# @global reporting.apiKey demo-reporting-api-key
# @global-secret reporting.sharedSecret shared-secret-value

### Bootstrap Reporting Session
# @name ReportsBootstrap
# @tag scripts pre-request
# @description Pre-request script seeds and reuses a global token while mutating headers and body.
# @rts pre-request
> let now = time.nowUnixMs()
> let token = vars.global.get("reporting.token") ?? "script-" + now
> vars.global.set("reporting.token", token, true)
> request.setHeader("Authorization", "Bearer " + token)
> request.setHeader("X-Trace-ID", "trace-" + now)
> request.setHeader("X-API-Key", vars.get("reporting.apiKey"))
> let payload = {
>   correlationId: "corr-" + now,
>   scope: "reports",
>   requestedAt: time.nowISO(),
> }
> request.setBody(json.stringify(payload, 2))
POST {{services.api.base}}/reports/sessions
Content-Type: application/json
Accept: application/json
X-Shared-Secret: {{reporting.sharedSecret}}

### List Reports With Script Token
# @name ReportsList
# @tag scripts reuse
# @description Uses the global token populated by the pre-request script along with the top-level API key.
# @auth bearer {{reporting.token}}
# @capture request reporting.lastTrace {{response.json.headers.X-Trace-Id}}
# @assert vars.get("reporting.token") => "global token should exist"
GET {{services.api.base}}/reports
Accept: application/json
X-API-Key: {{reporting.apiKey}}
X-Shared-Secret: {{reporting.sharedSecret}}

_examples/scripts.http on GitHub

Directives docs
Search

↑↓ moveEnter openEsc close

Help

These keys work like the ones in the TUI.

/
Search the docs (also Ctrl K)
j k
Scroll down and up
g g G
Jump to the top or the bottom
[ ]
Previous and next page
g d
Docs index
g h
Home page
t
Switch between dark and light
?
Show this help
Esc
Close a dialog