Overview
The HttpRequest block makes HTTP requests and returns the response. It supports all HTTP methods, headers, query parameters, and automatic JSON serialization.Input Parameters
Required
Parameter | Type | Description |
---|---|---|
url | string | The URL to request |
method | string | HTTP method (GET, POST, PUT, DELETE, PATCH, etc.) |
Optional
Parameter | Type | Default | Description |
---|---|---|---|
headers | object | {} | HTTP headers to send |
body | string/object | - | Request body (auto-serialized if object) |
query | object | - | Query parameters to append to URL |
timeout | number | 30000 | Request timeout in milliseconds |
Output Fields
Field | Type | Description |
---|---|---|
status | number | HTTP status code (200, 404, etc.) |
headers | object | Response headers |
body | string | Response body as text |
duration | number | Request duration in milliseconds |
url | string | Final URL (with query params if any) |
Examples
Simple GET Request
POST with JSON Body
- Object bodies are automatically JSON-serialized
Content-Type: application/json
is automatically added
GET with Query Parameters
https://api.example.com/users?page=2&limit=10&sort=name
PUT with String Body
Custom Timeout
Common Patterns
API Authentication
- Bearer Token
- API Key
- Basic Auth
REST Operations
- Create (POST)
- Read (GET)
- Update (PUT)
- Delete (DELETE)
Error Handling
The block returns an error if the request fails:- Network errors (connection refused, DNS failure)
- Timeout errors (request took longer than
timeout
ms) - Invalid URL errors
status
field in assertions:
Full Example
Tips
Always Parse JSON Responses
Always Parse JSON Responses
HttpRequest returns
body
as text. Use JsonParser to parse it:Use Context for Base URLs
Use Context for Base URLs
Store base URLs in context to avoid repetition:
Check Status in Assertions
Check Status in Assertions
Don’t rely on errors for HTTP status codes:
Increase Timeout for Slow Endpoints
Increase Timeout for Slow Endpoints
Default timeout is 30 seconds. Increase if needed: