HTTPRequest 1.0.0¶
Overview¶
Available Versions: 2.0.0 | 1.0.0 (current)
Description¶
Performs HTTP requests to web APIs and services using various methods (GET, POST, PUT, DELETE, PATCH). This block provides a flexible interface for making REST API calls with support for headers, query parameters, request bodies, and comprehensive error handling.
Key Features: - Support for all common HTTP methods - Configurable timeouts and headers - JSON request/response handling - Query parameter management - Detailed response information - Comprehensive error handling with status codes
Configuration Options¶
| Name | Data Type | Description | Default Value |
|---|---|---|---|
| timeout | int | Request timeout in seconds. Prevents hanging requests by setting maximum wait time for response. | 30 |
| method | HTTPMethod | HTTP method to use for the request (GET, POST, PUT, DELETE, PATCH). Determines the type of operation to perform. | GET |
| url | str | Target URL for the HTTP request. Can be overridden by input request object. Must include protocol (http/https). | "" |
| headers | dict[str, Any] | None | HTTP headers to include with the request. Common headers include Authorization, Content-Type, User-Agent. Can be overridden by input. | None |
| query_params | dict[str, Any] | None | URL query parameters to append to the request URL. Automatically URL-encoded. Can be overridden by input request object. | None |
| body | dict[str, Any] | None | Request body data for POST, PUT, PATCH requests. Automatically serialized as JSON. Ignored for GET/DELETE methods. | None |
Inputs¶
| Name | Data Type | Description |
|---|---|---|
| request | RequestObject | Can accept request parameters (method, url, headers, query_params, and/or body). Any values not specified will use the Config values. Pass an empty dict ({}) to use all Config values |
Outputs¶
| Name | Data Type | Description |
|---|---|---|
| response | ResponseObject | HTTP response containing status_code, headers, text content, raw content, and parsed body (for JSON responses). Provides complete response information for processing. |
Version History¶
- 2.0.0 - Sdk implementation
- 1.0.0 (Current) - Sdk implementation
Examples¶
# Simple GET request
- id: get_user_data
uses: HTTPRequest@1.0.0
with:
method: "GET"
url: "https://api.example.com/users/123"
headers:
Authorization: "Bearer your-token-here"
Content-Type: "application/json"
request: {}
outputs:
response: user_response
# POST request with JSON body
- id: create_user
uses: HTTPRequest@1.0.0
with:
method: "POST"
url: "https://api.example.com/users"
headers:
Authorization: "Bearer your-token-here"
Content-Type: "application/json"
body:
name: "John Doe"
email: "john.doe@example.com"
role: "user"
request: {}
outputs:
response: create_response
# GET with query parameters
- id: search_products
uses: HTTPRequest@1.0.0
with:
method: "GET"
url: "https://api.example.com/products"
query_params:
category: "electronics"
page: 1
limit: 10
request: {}
outputs:
response: products_response
Error Handling¶
HTTPNetworkError
- Error Code
network_error_occurred- Common Cause
- Network connectivity issues, DNS resolution failures, or server unavailability
- Solution
- Check internet connectivity, verify URL is correct, ensure target server is accessible, implement retry logic with backoff
HTTPStatusError
- Error Code
http_status_error- Common Cause
- Server returned HTTP error status codes (4xx client errors, 5xx server errors)
- Solution
- Check API documentation for error meanings, verify authentication tokens, validate request format, handle specific status codes appropriately
RequestTimeoutError
- Error Code
request_timeout_exceeded- Common Cause
- Request took longer than the configured timeout value to complete
- Solution
- Increase timeout value for slow APIs, optimize request payload size, check server performance, implement proper timeout handling
JSONParsingError
- Error Code
json_response_parsing_failed- Common Cause
- Server response claimed to be JSON but contained invalid JSON format
- Solution
- Check API response format, handle non-JSON responses appropriately, verify Content-Type headers, use response.text for debugging
FAQ¶
How do I handle authentication with APIs?
Use the headers configuration for common auth methods: Bearer tokens (Authorization: "Bearer token"), API keys (X-API-Key: "key"), or Basic auth (Authorization: "Basic encoded-credentials"). Some APIs also use query parameters for authentication.
What's the difference between config and input request parameters?
Configuration values are static defaults set at design time. Input request parameters can override config values dynamically at runtime. If a request parameter is provided, it takes precedence over the corresponding config value.
How do I handle different response content types?
The response object includes both text and content fields. JSON responses are automatically parsed into the body field. For other formats, use response.text for text content or response.content for binary data. Check response.headers for Content-Type information.
How can I handle HTTP errors in my workflow?
HTTP errors (4xx, 5xx) raise HTTPError exceptions with status codes and response details. Use conditional blocks or error handling workflows to manage different status codes. The error includes the full response object for detailed error analysis.
What happens when a request times out?
Requests exceeding the timeout value (default 30 seconds) will raise an HTTPError. Configure appropriate timeout values based on API response times. Consider implementing retry logic for timeout-sensitive operations or increase timeout for slow APIs.