httpRequest
The httpRequest action makes arbitrary HTTP calls, allowing you to interact with and validate APIs or other web services directly within your tests.
You can specify a basic GET request using a string shorthand or use an object for more complex requests and validation:
- String Shorthand: Provide the URL directly as the value for the
httpRequestkey. This performs a basic GET request to that URL. - Object Format: Use an object with the following properties:
url: (Required unless usingopenApi) The target URL. Use an absolute URL, a path that starts with one/, or a value that starts with a variable, such as$API_URL/users. Doc Detective joins a path to the globaloriginfrom the configuration and appends itsoriginParams. Without anorigin, a path fails the step. WithopenApi, a path still joins the configuration’sorigin, not the OpenAPIserver.method: (Optional) The HTTP method (for example,get,post,put,patch, ordelete). Case is normalized, soGETalso works. Defaults toget.timeout: (Optional) Maximum duration in milliseconds to wait for the request to complete.request: (Optional) An object defining the request details:headers: (Optional) Request headers, as either key-value pairs with string values or a newline-separated string block such asContent-Type: application/json\nAuthorization: Bearer token. In the string form, Doc Detective splits each line on its first colon. Header values can therefore contain colons themselves, including full URLs, timestamps like12:00:00 GMT, andhost:portvalues.parameters: (Optional) Key-value pairs for query string parameters.body: (Optional) The request body. Can be a string or JSON object.
response: (Optional) An object defining expected response validation:headers: (Optional) Key-value pairs for expected response headers. Values must be strings.body: (Optional) Expected response body. Can be a string or JSON object.required: (Optional) Array of field paths that must exist in the response body. Uses dot notation for nested fields (for example,user.name) and bracket notation for array indices (for example,items[0].id). Fields can have any value, includingnull.
allowAdditionalFields: (Optional) Whether the response may contain fields beyond those declared inresponse.body. Defaults totrue. Set it tofalseto fail the step when the response includes any field not declared inresponse.body. The check is recursive. It descends into nested objects and names each undeclared field by its dot-path, such asuser.extra. It applies only when the top-levelresponse.bodydeclares fields. Whenresponse.bodyis unset or empty, the response has no key constraint and the check passes. A nested empty object still constrains. Aresponse.bodyof{ "user": {} }requiresuserto be empty, so any field under it fails the step.statusCodes: (Optional) An acceptable HTTP status code, or an array of them. If the response code isn’t in this list, the step fails (default:[200, 201]).openApi: (Optional) Define the request based on an OpenAPI definition. Can be a string (operation ID) or an object:name: (Optional) Name of the registered OpenAPI definition (if multiple are loaded).descriptionPath: (Optional) Path or URL to the OpenAPI description file.operationId: (Required) The ID of the operation to use.server: (Optional) Base server URL for the request. If omitted, Doc Detective uses the first server defined in the OpenAPI description.validateAgainstSchema: (Optional) Which parts of the request and response to validate against the OpenAPI schema (request,response,both, ornone). The step fails on a mismatch. Defaults toboth.mockResponse: (Optional) Whentrue, skips the HTTP request and uses the response example or schema from the OpenAPI description as the response data. Useful for testing an API that isn’t fully implemented yet. IfstatusCodeisn’t set, Doc Detective uses the first response code defined for the operation.statusCode: (Optional) Response code to use for validation, examples, and status-code checking. Doc Detective adds this code to the step’s acceptedstatusCodes. WithoutstatusCodeorstatusCodes, the step accepts the operation’s2xxresponse codes instead of[200, 201].useExample: (Optional) Which parts of the request and response to populate with example data from the OpenAPI description (request,response,both, ornone). Defaults tonone.exampleKey: (Optional) Key of the specific example to use if multiple exist.headers: (Optional) Request headers to add to every request built from the definition, such as anAuthorizationheader, in the same two forms asrequest.headers. A step-level value overrides a matching header set in your configuration, andrequest.headersoverride these by name. Note: Properties likerequest.headers,request.parameters,request.bodycan override values from the OpenAPI definition or example.
- Output Saving: You can also save the response body using
path,directory,maxVariation, andoverwriteproperties. The saved file shows environment variable values as***NAME***. See Saved files and thehttpRequestreference.
Setting Variables: To capture parts of the response for later steps, use the step-level variables object. You can assign values based on the response using expressions like $$response.body, $$response.headers, $$response.status, etc. You can use dot notation for nested JSON fields (for example, $$response.body.user.id).
Depending on which validations you configure, the action also exposes the result of each check in its outputs object. To capture any of them for later steps, use the step-level variables object with the matching expression. Each output is present only when its check applies:
$$requiredFieldsPresent: whether every field inresponse.requiredwas found (whenresponse.requiredis set).$$bodyMatches: whether the response body matchedresponse.body(whenresponse.bodyis set).$$headersMatch: whether the expectedresponse.headerswere present (whenresponse.headersis set).$$noUnexpectedFields: whether the response contained only expected fields (whenallowAdditionalFieldsisfalse).$$responseSchemaValid: whether the response matched the OpenAPI schema (when validating the response against an OpenAPI definition).$$variation: the fractional difference between the new response and the reference file (when you save the response withpathand a reference file already exists).
For comprehensive options, see the
httpRequestreference.
Reports show environment variable values in the URL, headers, body, and response as ***NAME***, including a Basic auth token that holds one. Response checks compare the real values. See Keep secrets out of logs, reports, and captures.
Examples
The docs tests run every example below except the string-or-array body example and the save-and-timeout example.
Basic GET request (string shorthand)
Basic GET request (object format)
POST request with JSON body
PUT request with headers and query parameters
Update fields with a PATCH request
A PATCH request sends only the fields you want to change.
Delete a resource with a DELETE request
A DELETE request removes a resource. APIs vary in the status they return. Set statusCodes to the codes yours uses, such as 200 or 204.
Send request headers as a string block
You can also provide request.headers as a single newline-separated string instead of an object. Doc Detective splits each line on its first colon into a name and value. Values that contain colons, such as callback URLs or timestamps, stay intact.
Send a string or array request body
request.body accepts a JSON object, a JSON array, or a raw string. Doc Detective sends an object or array as JSON. It sends a string unchanged, so set the matching Content-Type header yourself. The same three shapes apply to response.body when you validate the response.
Validate response status code and body
Use OpenAPI definition (by operation ID)
Assumes an OpenAPI definition with operation ID getUserById is loaded.
Use OpenAPI definition (detailed object)
Set a variable from response body
Save the response body and set a timeout
Save the response with path and directory, and cap the request with a timeout in milliseconds. On later runs, maxVariation and overwrite compare the new response against the saved copy.
Validate fields with dynamic values
When testing APIs that return unpredictable values (like timestamps, UUIDs, or session tokens), you can verify that fields exist without asserting their exact values.
Validate nested fields and arrays
Use dot notation for nested object fields and bracket notation for array elements to validate complex response structures.
Combine required fields with body validation
You can use both response.required and response.body together to validate that certain fields exist while asserting specific values for others.
Note: Fields with
null,"",0, orfalsevalues are considered to exist and will pass validation.
Reject unexpected response fields
Set allowAdditionalFields to false to assert that the response contains only the fields you declared in response.body. The step fails if the response includes any extra field.
The check descends into nested objects. It catches an extra field at any depth and names it by its dot-path. A nested empty object is still a constraint. Declaring "user": {} in response.body requires the response’s user object to be empty, so any field it carries fails the step. Only an unset or empty top-level response.body lifts the constraint entirely.