Skip to content

labs/http

Step Summary
labs/http/api_request Call one operation of an API file directly, and return its answer.
labs/http/api_sweep Call many operations of an API file and check every answer against the document.

labs/http/api_request

Call one operation of an API file directly, and return its answer.

The step builds the request from the document: the method and path of the operation, its placeholders filled from path_params and percent-encoded, the query and headers given, Accept from the documented answers. A required parameter or body that is missing, or a header value carrying CR or LF, fails the step before anything is sent. The request goes to base_url and nowhere else: redirects are not followed, and answers over 10 MiB are refused rather than read. Put labs/validate/api_response under validate: to check the answer against what the operation documents.

Inputs

Parameter Type Required Default Also accepts Description
headers object no {} — Extra HTTP headers merged into the request.
timeout number no None — Request timeout in seconds; the test's default is used when omitted.
api any yes — — The API file, written '${{ env.apis. }}'. Recorded by its id and digest, never as the document.
operation string yes — — The operation: its operationId, or 'METHOD /path' exactly as the document writes the path.
path_params object no {} — Values of the path's placeholders, by name; each is percent-encoded as one segment.
query object no {} — Query parameters, by name; a list repeats the parameter. Plugs in the 'query' that 'security/api_key' returns.
body any no None — Request body; an object or list is sent as JSON, text as it is.
content_type string no None — Content-Type of the body; omitted, the operation's first documented one (JSON if documented).
accept string no None — Accept header; omitted, the media types the operation documents for its 2XX answers.
expect integer | string no None — The answer the test expects: a status (404), a class ('4XX'), 'success' (2XX) or 'error' (400 and up). Another answer fails the step. A request expected to be refused with a 4xx counts as sent wrong on purpose for 'labs/validate/api_errors'.
base_url string no None — URL the operation's path is appended to, e.g. 'https://sut.example.com/api'. Omitted, the document's first server URL (absolute http(s) only, its variables at their defaults).

Output — the value assertions and returns: read

Output contract of the API call steps: the answer and the operation it answers.

Field Type Description
status_code integer Status the API answered with.
response_body any Body: parsed JSON for a JSON media type, else text.
response_headers object Response headers, with the casing the server sent.
operation ApiOperationRef The operation called.

labs/http/api_sweep

Call many operations of an API file and check every answer against the document.

Safe by default: only GET and HEAD, and a write only when it is listed in operations and include_writes is true. Each operation's required parameters come from params (path and query, by name) and headers; one with a value missing is skipped and its row says which. Every call goes to base_url — the document's per-operation servers are never followed, nor are redirects — at most concurrency at a time, each within timeout and all within budget_s. Each answer is checked as labs/validate/api_response checks one; the step fails when any is not what its operation documents, and keeps the table either way.

Inputs

Parameter Type Required Default Also accepts Description
headers object no {} — Extra HTTP headers merged into the request.
timeout number no None — Request timeout in seconds; the test's default is used when omitted.
api any yes — — The API file, written '${{ env.apis. }}'. Recorded by its id and digest, never as the document.
base_url string no None — URL every operation's path is appended to; omitted, the document's first server URL.
operations list of string no [] — Only these operations (operationId or 'METHOD /path'); a write must be listed here.
tags list of string no [] — Only operations with one of these tags.
methods list of string no ['GET', 'HEAD'] — Only operations with one of these methods.
exclude list of string no [] — Operations never called.
include_writes boolean no False — Call the writes listed in 'operations' (POST, PUT, PATCH, DELETE); off by default.
params object no {} — Path and query parameter values by name, shared by every operation; an operation missing a required one is skipped.
query object no {} — Query parameters sent with every call, e.g. the 'query' 'security/api_key' returns.
bodies object no {} — Request bodies by operationId (or 'METHOD /path'), for listed writes.
concurrency integer no 4 — Calls in flight at once.
budget_s number no 300 — Seconds the whole sweep may take; calls not started by then are skipped.

Output — the value assertions and returns: read

Output contract of labs/http/api_sweep.

Field Type Description
results list of SweepRow One row per operation, in document order.
called integer Operations called.
passed integer Calls whose answer the operation documents.
failed integer Calls whose answer it does not, or that failed.
skipped integer Operations not called, with the reason in their row.

Nested objects

ApiOperationRef

The operation an answer belongs to.

Field Type Required Default Also accepts Description
api string yes — — Id of the API file, as declared in env.apis.
id string no None — operationId, when the document gives one.
method string yes — — HTTP method.
path string yes — — Path template, as the document writes it.

SweepRow

One operation of the sweep and what became of it.

Field Type Required Default Also accepts Description
operation string yes — — operationId, else 'METHOD /path'.
method string yes — — HTTP method.
path string yes — — Path template.
status integer no None — Status answered; none when not called.
verdict string yes — — 'passed', 'failed', 'skipped' or 'error'.
problems list of string no [] — What was wrong, or why it was skipped.
duration_ms number no 0 — Time the call took, in milliseconds.