at.response

The at.response namespace is the handle to the HTTP response for the current request. It is only populated in post-scripts — in pre-scripts and lifecycle scripts it is an empty object, because no response has been received yet.

Properties and Methods

All response data is exposed through a small set of properties and a single parsing helper. Every property is a getter — nothing on at.response is a function except json().

  • at.response.status — the HTTP status code as a number (for example 200 or 404). This is a property, not a method — write at.response.status, not at.response.status().
  • at.response.statusText — the HTTP status reason phrase as a string (for example "OK" or "Not Found").
  • at.response.headers — a plain object of response header key-value pairs (a copy — mutating it has no effect).
  • at.response.body — the response body as a raw string. Empty responses come back as "".
  • at.response.timing — an object with timing information in milliseconds: { total, dns, tls, ttfb }. dns, tls, and ttfb may be missing for cached or non-TLS responses. In load test step scripts, only total is present.
  • at.response.json() — parses the response body as JSON and returns the parsed value. Safe to call multiple times inside the same post-script: main-engine scripts cache the first parse and return the same object on every later call; load test step scripts re-parse on each call (still safe, just not cached). Empty-body edge case: in main-engine scripts json() throws SyntaxError on a genuinely empty body (because JSON.parse("") fails), while load test step scripts return null. Guard with if (at.response.body) before calling json() if an empty body is possible.

When at.response Is Populated

at.response is only populated in post-scripts, because that is the only time a response exists:

  • Post-script: all properties and json() work.
  • Pre-script: at.response is an empty object. Reading any property returns undefined; calling json() throws.
  • Lifecycle (Before All / After All): also empty. There is no single response to describe at lifecycle scope.

Example — Response Inspection and Token Extraction

Post-script:

// Inspect the response. Note: at.response.status is a property, not a method.
console.log("Status:", at.response.status, at.response.statusText);

// Parse the JSON body (cached — safe to call multiple times).
const data = at.response.json();

// Save extracted values to the environment.
if (at.response.status === 200) {
  at.environment.set("user_id", String(data.id));
  at.environment.set("session_token", data.token);
}

// Check performance and warn about slow responses.
const timing = at.response.timing;
if (timing && timing.total > 2000) {
  console.warn("Slow response:", timing.total, "ms");
}

Tip — Prefer json() Over JSON.parse

Use at.response.json()rather than JSON.parse(at.response.body)whenever possible. The built-in helper keeps the call site short and is the idiomatic way to reach for the parsed payload in a post-script. For endpoints that may legitimately return an empty body, check at.response.bodyfirst — see the empty-body note on json()above.