Response object
The res object is available inside the vars, assertions, scripting, and testing contexts. Use it to extract values from the response body, headers, and status.
The res object is only available in the res tab in the context of a response from a request.
You can also query nested response data using response queries.
Properties
| Property | Description |
|---|---|
res.status |
HTTP status code (e.g., 200, 404) |
res.statusText |
HTTP status text (e.g., "OK", "Not Found") |
res.headers |
Key-value pairs of HTTP response headers |
res.body |
The parsed response body (string, object, etc.) |
res.responseTime |
Time in milliseconds the request took to complete |
res.url |
The full URL of the request |
Methods
| Method | Description |
|---|---|
res.getStatus() |
Returns the HTTP status code |
res.getStatusText() |
Returns the HTTP status text |
res.getHeader(name) |
Returns the value of a specific response header |
res.getHeaders() |
Returns all response headers |
res.getBody() |
Returns the response body |
res.getResponseTime() |
Returns the response time in milliseconds |
res.getUrl() |
Returns the request URL |
res.setBody(data) |
Replaces the response body with new data |
res.getSize() |
Returns an object with header, body, and total byte sizes |
Example usage
// Accessing response properties
let status = res.status; // 200
let statusText = res.statusText; // "OK"
let contentType = res.headers['content-type']; // "application/json"
let body = res.body; // { message: "Hello, world!" }
let time = res.responseTime; // 120
let url = res.url; // "https://api.example.com/data"
// Using getter methods
let headerVal = res.getHeader('content-type');
let allHeaders = res.getHeaders();
let size = res.getSize(); // { header: 234, body: 1024, total: 1258 }
// Modifying the response body for downstream scripts
res.setBody({ message: "Modified response" });