>_ RESTERM
v1.18.2

examples Variables and auth

scopes.http

Global, file, and request variables and captures, checked with @assert.

runs as-is

shell
resterm run --all _examples/scopes.http

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

Editor
### Seed Analytics Session
# @name AnalyticsSeedSession
# @description Demonstrates @global, @var file/request, and capture scopes working together.
# @tag analytics session
# @global analytics.apiKey demo-analytics-key
# @var file analytics.baseUrl https://httpbin.org/anything/analytics
# @var file analytics.defaultRange last-30-days
# @var request analytics.jobId job-{{$uuid}}
# @var request analytics.requestToken session-{{$uuid}}
# @capture global-secret analytics.sessionToken {{response.json.json.sessionToken}}
# @capture file analytics.lastJobId {{response.json.json.jobId}}
# @capture request analytics.trace {{response.json.headers.X-Amzn-Trace-Id}}
POST {{analytics.baseUrl}}/sessions
Content-Type: application/json
Authorization: Bearer {{analytics.requestToken}}
X-API-Key: {{analytics.apiKey}}
X-Job-ID: {{analytics.jobId}}

{
  "jobId": "{{analytics.jobId}}",
  "sessionToken": "{{analytics.requestToken}}",
  "range": "{{analytics.defaultRange}}",
  "tenant": "{{tenant.id}}"
}

### Retrieve Last Analytics Job
# @name AnalyticsFetchJob
# @tag analytics read
# @description Reuses captured globals and file variables while showing request-scope captures.
# @var request analytics.traceId {{$uuid}}
# @capture request echoed.authorization {{response.json.headers.Authorization}}
# @assert vars.get("analytics.sessionToken") => "captured session token is available"
# @assert vars.get("analytics.sessionToken") in vars.get("echoed.authorization") => "Authorization header includes captured token"
# @assert vars.get("analytics.traceId") => "request-scope value should be visible to tests"
GET {{analytics.baseUrl}}/jobs/{{analytics.lastJobId}}
Authorization: Bearer {{analytics.sessionToken}}
X-API-Key: {{analytics.apiKey}}
X-Trace-ID: {{analytics.traceId}}
Accept: application/json

_examples/scopes.http on GitHub

Captures 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