The Spectral HTTP client is built on top of Axios and provides helpers for creating authenticated clients, handling retries, uploading files, and building generic raw request actions. Import fromDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/prismatic-io/spectral/llms.txt
Use this file to discover all available pages before exploring further.
@prismatic-io/spectral/dist/clients/http:
createClient
Creates a reusable Axios HTTP client instance configured with a base URL, default headers, timeout, and optional retry logic.
https://api.acme.com/v2/). All relative request URLs are resolved against this.'json' to automatically parse a JSON response, or 'arraybuffer' for binary data. Passed directly to Axios.Authorization header).true, logs every request and response to the console. Useful during development.Basic usage
HttpClient type
HttpClient is a type alias for an Axios instance:
.get(), .post(), .put(), .patch(), .delete(), .request(), and so on.
RetryConfig
Pass a retryConfig object to createClient to automatically retry failed requests.
exponentialDelay and isNetworkOrIdempotentRequestError
These are re-exported from axios-retry for convenience.
exponentialDelay— A pre-built delay function that doubles the wait after each retry attempt.isNetworkOrIdempotentRequestError— The default retry condition. Returnstruefor network errors and idempotent HTTP methods with 5xx responses.
Authorization helpers
toAuthorizationHeaders
Inspects a Spectral Connection object and returns an Authorization header automatically. The detection order is:
- OAuth access token — if
connection.token.access_tokenis set, returns{ Authorization: "Bearer <token>" }. - API key — if
connection.fields.apiKeyis set, returns{ Authorization: "Bearer <apiKey>" }. - Username / password — if both
connection.fields.usernameandconnection.fields.passwordare set, returns{ Authorization: "Basic <base64(user:pass)>" }. - Error — throws if none of the above are present.
- Bearer token
- API key
- Basic auth
Form data and file uploads
The HTTP client supports multipart form uploads through thesendRawRequest function and the built-in inputs. For direct use, construct a FormData instance and pass it as the request body. The client automatically sets the correct Content-Type: multipart/form-data boundary headers.
sendRawRequest function calls an internal toFormData helper that converts a list of {key, value} pairs into a FormData object and uses util.types.toBufferDataPayload to handle file data.handleErrors
A global error handler that enriches Axios errors with structured response details.
message— the error message stringdata— the response bodystatus— the HTTP status codeheaders— the response headers
sendRawRequest
Executes a fully configured HTTP request from a set of input values. Used internally by buildRawRequestAction to power raw request actions.
buildRawRequestAction
Generates a ready-to-use Spectral action that exposes all HTTP request inputs (method, URL, headers, query params, body, form data, file data, timeouts, retries, and response type) and performs the request against a fixed base URL.
Built-in inputs
Theinputs export from the HTTP client package is a map of pre-configured Spectral inputs. You can spread them directly into an action’s inputs object.
url — required string
url — required string
/sobjects/Account). Combined with the client’s baseUrl.method — required string
method — required string
DELETE, GET, HEAD, LINK, OPTIONS, PATCH, POST, PURGE, PUT, UNLINK.data — optional string
data — optional string
{"exampleKey": "Example Data"}).formData — optional key-value list
formData — optional key-value list
fileData — optional key-value list
fileData — optional key-value list
fileDataFileNames — optional key-value list
fileDataFileNames — optional key-value list
fileData key. Keys must match fileData keys.headers — optional key-value list
headers — optional key-value list
User-Agent: curl/7.64.1).queryParams — optional key-value list
queryParams — optional key-value list
?key1=value1&key2=value2).responseType — default 'json'
responseType — default 'json'
arraybuffer, document, json, or text.timeout — optional number (ms)
timeout — optional number (ms)
maxRetries — default 0
maxRetries — default 0
0 to disable retries.retryDelayMS — default 0
retryDelayMS — default 0
useExponentialBackoff is false.retryAllErrors — default false
retryAllErrors — default false
true, retries on all error responses including HTTP 429 and other 4xx codes. When false, only retries on 5xx and network errors.useExponentialBackoff — default false
useExponentialBackoff — default false
true, enables exponential backoff between retry attempts. retryDelayMS is ignored when this is enabled.debugRequest — optional boolean
debugRequest — optional boolean
true, logs the current request and response to the console.