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
resterm run --all _examples/scripts.httpRun this from the root of a clone of the Resterm repository.
Editor
Directives docs# 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}}