Skip to main content

Overview

The HttpRequest block makes HTTP requests and returns the response. It supports all HTTP methods, headers, query parameters, and automatic JSON serialization.
{
  "block": "HttpRequest",
  "input": {
    "url": "https://api.example.com/users",
    "method": "GET"
  },
  "output": "response"
}

Input Parameters

Required

ParameterTypeDescription
urlstringThe URL to request
methodstringHTTP method (GET, POST, PUT, DELETE, PATCH, etc.)

Optional

ParameterTypeDefaultDescription
headersobject{}HTTP headers to send
bodystring/object-Request body (auto-serialized if object)
queryobject-Query parameters to append to URL
timeoutnumber30000Request timeout in milliseconds

Output Fields

FieldTypeDescription
statusnumberHTTP status code (200, 404, etc.)
headersobjectResponse headers
bodystringResponse body as text
durationnumberRequest duration in milliseconds
urlstringFinal URL (with query params if any)

Examples

Simple GET Request

{
  "block": "HttpRequest",
  "input": {
    "url": "https://api.example.com/users/1",
    "method": "GET"
  },
  "output": "response"
}
Output:
{
  status: 200,
  headers: { "content-type": "application/json" },
  body: '{"id": 1, "name": "John"}',
  duration: 245,
  url: "https://api.example.com/users/1"
}

POST with JSON Body

{
  "block": "HttpRequest",
  "input": {
    "url": "https://api.example.com/users",
    "method": "POST",
    "headers": {
      "Authorization": "Bearer ${token}"
    },
    "body": {
      "name": "John Doe",
      "email": "john@example.com"
    }
  },
  "output": "createResponse"
}
Notes:
  • Object bodies are automatically JSON-serialized
  • Content-Type: application/json is automatically added

GET with Query Parameters

{
  "block": "HttpRequest",
  "input": {
    "url": "https://api.example.com/users",
    "method": "GET",
    "query": {
      "page": "2",
      "limit": "10",
      "sort": "name"
    }
  },
  "output": "response"
}
Final URL: https://api.example.com/users?page=2&limit=10&sort=name

PUT with String Body

{
  "block": "HttpRequest",
  "input": {
    "url": "https://api.example.com/data",
    "method": "PUT",
    "headers": {
      "Content-Type": "text/plain"
    },
    "body": "Raw text content"
  },
  "output": "response"
}

Custom Timeout

{
  "block": "HttpRequest",
  "input": {
    "url": "https://api.example.com/slow-endpoint",
    "method": "GET",
    "timeout": 60000
  },
  "output": "response"
}

Common Patterns

API Authentication

  • Bearer Token
  • API Key
  • Basic Auth
{
  "input": {
    "url": "${BASE_URL}/protected",
    "method": "GET",
    "headers": {
      "Authorization": "Bearer ${authToken}"
    }
  }
}

REST Operations

  • Create (POST)
  • Read (GET)
  • Update (PUT)
  • Delete (DELETE)
{
  "block": "HttpRequest",
  "input": {
    "url": "${BASE_URL}/users",
    "method": "POST",
    "body": {
      "name": "John",
      "email": "john@example.com"
    }
  },
  "output": "created"
}

Error Handling

The block returns an error if the request fails:
{
  error: "Failed to fetch",
  status: 0,
  duration: 1234,
  url: "https://api.example.com/users"
}
Common errors:
  • Network errors (connection refused, DNS failure)
  • Timeout errors (request took longer than timeout ms)
  • Invalid URL errors
Note: HTTP error status codes (4xx, 5xx) are not treated as errors. Check the status field in assertions:
{
  "assertions": {
    "response.status": 200
  }
}

Full Example

{
  "name": "User API Test",
  "context": {
    "BASE_URL": "https://api.example.com",
    "API_KEY": "${env.API_KEY}"
  },
  "tests": [{
    "id": "create-user",
    "pipeline": [
      {
        "block": "HttpRequest",
        "input": {
          "url": "${BASE_URL}/users",
          "method": "POST",
          "headers": {
            "Authorization": "Bearer ${API_KEY}",
            "Content-Type": "application/json"
          },
          "body": {
            "name": "John Doe",
            "email": "john@example.com",
            "role": "admin"
          },
          "timeout": 5000
        },
        "output": "createResponse"
      },
      {
        "block": "JsonParser",
        "input": "${createResponse.body}",
        "output": {
          "parsed": "newUser"
        }
      }
    ],
    "assertions": {
      "createResponse.status": 201,
      "newUser.id": { "gt": 0 },
      "newUser.email": "john@example.com"
    }
  }]
}

Tips

HttpRequest returns body as text. Use JsonParser to parse it:
{
  "pipeline": [
    {
      "block": "HttpRequest",
      "output": "response"
    },
    {
      "block": "JsonParser",
      "input": "${response.body}",
      "output": { "parsed": "data" }
    }
  ]
}
Store base URLs in context to avoid repetition:
{
  "context": {
    "BASE_URL": "${env.API_URL}",
    "API_KEY": "${env.API_KEY}"
  },
  "tests": [{
    "pipeline": [{
      "block": "HttpRequest",
      "input": {
        "url": "${BASE_URL}/endpoint"
      }
    }]
  }]
}
Don’t rely on errors for HTTP status codes:
{
  "assertions": {
    "response.status": { "lt": 400 }
  }
}
Default timeout is 30 seconds. Increase if needed:
{
  "input": {
    "url": "${BASE_URL}/slow",
    "method": "GET",
    "timeout": 120000
  }
}

Next Steps

I