Skip to main content
Version: 1.0.1

HTTP Worker

The HTTP Worker is a powerful, general-purpose worker that can make HTTP requests to any endpoint. It supports all HTTP methods, multiple authentication types, retry policies, and response validation.

Features

  • All HTTP methods (GET, POST, PUT, DELETE, PATCH, HEAD, OPTIONS)
  • Multiple authentication types (Basic, Bearer, API Key, OAuth2)
  • Request body support (JSON, XML, Form, Multipart, Binary)
  • Path and query parameters
  • Custom headers and cookies
  • Retry policies with exponential backoff
  • Response validation (status codes, body content, JSONPath)
  • Proxy support
  • Client certificates (mTLS)
  • SSL/TLS configuration

Use Cases

ScenarioExample
Webhook TriggersCall external APIs on schedule
Health ChecksMonitor external service availability
Data SyncFetch data from REST APIs periodically
NotificationsSend HTTP-based notifications (Slack, Teams, Discord)
Report GenerationTrigger report generation endpoints
Cache WarmingPre-populate caches by calling endpoints

Job Data Schema

When creating a job with the HTTP Worker, you provide configuration through the Job Data JSON:

{
"url": "https://api.example.com/users/{userId}",
"method": "POST",
"headers": {
"X-Custom-Header": "value"
},
"queryParameters": {
"include": "details"
},
"pathParameters": {
"userId": "123"
},
"body": {
"type": "Json",
"content": {
"name": "John Doe",
"email": "[email protected]"
}
},
"authentication": {
"type": "Bearer",
"credential": "your-api-token"
},
"timeoutSeconds": 30,
"retryPolicy": {
"maxRetries": 3,
"initialDelayMs": 1000,
"backoffMultiplier": 2.0
},
"validation": {
"expectedStatusCodes": [200, 201],
"bodyContains": "success"
}
}

Configuration Reference

Main Properties

PropertyTypeRequiredDefaultDescription
urlstring-Target URL. Supports path parameters like {userId}
methodenum-GETHTTP method: GET, POST, PUT, DELETE, PATCH, HEAD, OPTIONS
headersobject--Custom request headers as key-value pairs
queryParametersobject--Query string parameters to append to URL
pathParametersobject--Values to replace URL placeholders like {id}
bodyobject--Request body configuration
authenticationobject--Authentication settings
timeoutSecondsnumber-30Request timeout in seconds
followRedirectsboolean-trueWhether to follow HTTP redirects
maxRedirectsnumber-5Maximum redirects to follow
ignoreSslErrorsboolean-falseSkip SSL certificate validation (use with caution!)
retryPolicyobject--Retry configuration for failed requests
validationobject--Response validation rules
proxyobject--HTTP proxy configuration
clientCertificateobject--Client certificate for mTLS
userAgentstring-Milvaion-HttpWorker/1.0Custom User-Agent header
cookiesobject--Cookies to send with request

Request Body Configuration

{
"body": {
"type": "Json",
"content": { "key": "value" },
"encoding": "utf-8",
"contentTypeOverride": "application/json"
}
}
PropertyTypeDefaultDescription
typeenumJsonBody type: Json, Xml, Text, FormUrlEncoded, Multipart, Binary, GraphQL, Html, None
contentany-Body content (JSON object, string, or base64 for binary)
formDataobject-Form fields for FormUrlEncoded or Multipart
filesarray-File uploads for Multipart requests
encodingstringutf-8Character encoding
contentTypeOverridestring-Override default Content-Type header
Multipart File Upload
{
"body": {
"type": "Multipart",
"formData": {
"description": "My file upload"
},
"files": [
{
"fieldName": "file",
"fileName": "document.pdf",
"contentBase64": "JVBERi0xLjQK...",
"contentType": "application/pdf"
}
]
}
}

Authentication Types

Bearer Token
{
"authentication": {
"type": "Bearer",
"credential": "your-jwt-token"
}
}
Basic Authentication
{
"authentication": {
"type": "Basic",
"credential": "username",
"secret": "password"
}
}
API Key
{
"authentication": {
"type": "ApiKey",
"credential": "your-api-key",
"keyName": "X-API-Key",
"keyLocation": "Header"
}
}
keyLocationDescription
HeaderSend as HTTP header (default)
QuerySend as query parameter
CookieSend as cookie
OAuth2 (Client Credentials)
{
"authentication": {
"type": "OAuth2",
"tokenUrl": "https://auth.example.com/oauth/token",
"clientId": "your-client-id",
"clientSecret": "your-client-secret",
"scopes": ["read", "write"],
"grantType": "ClientCredentials"
}
}
grantTypeDescription
ClientCredentialsServer-to-server authentication (default)
PasswordResource owner password credentials
AuthorizationCodeAuthorization code flow
RefreshTokenRefresh an existing token

Retry Policy

{
"retryPolicy": {
"maxRetries": 3,
"initialDelayMs": 1000,
"maxDelayMs": 30000,
"backoffMultiplier": 2.0,
"retryOnStatusCodes": [408, 429, 500, 502, 503, 504],
"retryOnTimeout": true,
"retryOnConnectionError": true
}
}
PropertyDefaultDescription
maxRetries3Maximum retry attempts
initialDelayMs1000Initial delay between retries (ms)
maxDelayMs30000Maximum delay between retries (ms)
backoffMultiplier2.0Multiplier for exponential backoff
retryOnStatusCodes[408, 429, 500, 502, 503, 504]Status codes that trigger retry
retryOnTimeouttrueRetry on request timeout
retryOnConnectionErrortrueRetry on connection failures

Response Validation

{
"validation": {
"expectedStatusCodes": [200, 201, 204],
"bodyContains": "success",
"bodyNotContains": "error",
"jsonPathExpression": "$.data.id",
"jsonPathExpectedValue": "123",
"requiredHeaders": {
"Content-Type": "application/json"
},
"maxResponseSizeBytes": 1048576
}
}
PropertyDescription
expectedStatusCodesArray of acceptable status codes
bodyContainsFail if body doesn't contain this text
bodyNotContainsFail if body contains this text
jsonPathExpressionJSONPath to extract value (e.g., $.data.id)
jsonPathExpectedValueExpected value at JSONPath location
requiredHeadersHeaders that must be present in response
maxResponseSizeBytesMaximum allowed response size

Proxy Configuration

{
"proxy": {
"url": "http://proxy.company.com:8080",
"username": "proxyuser",
"password": "proxypass",
"bypassList": ["localhost", "*.internal.com"]
}
}

Client Certificate (mTLS)

{
"clientCertificate": {
"certificateBase64": "MIIE...",
"password": "cert-password"
}
}

Or using Windows certificate store:

{
"clientCertificate": {
"thumbprint": "1234567890ABCDEF...",
"storeLocation": "CurrentUser"
}
}

Practical Examples

Example 1: Simple GET Request

{
"url": "https://api.github.com/users/octocat",
"method": "GET",
"headers": {
"Accept": "application/vnd.github.v3+json"
}
}

Example 2: POST with JSON Body

{
"url": "https://api.example.com/orders",
"method": "POST",
"authentication": {
"type": "Bearer",
"credential": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."
},
"body": {
"type": "Json",
"content": {
"productId": "PROD-001",
"quantity": 5,
"customerId": "CUST-123"
}
},
"validation": {
"expectedStatusCodes": [201],
"jsonPathExpression": "$.orderId"
}
}

Example 3: Slack Notification

{
"url": "https://hooks.slack.com/services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX",
"method": "POST",
"body": {
"type": "Json",
"content": {
"text": "Daily report generated successfully! 📊",
"channel": "#reports"
}
}
}

Example 4: Health Check with Validation

{
"url": "https://api.myservice.com/health",
"method": "GET",
"timeoutSeconds": 10,
"validation": {
"expectedStatusCodes": [200],
"jsonPathExpression": "$.status",
"jsonPathExpectedValue": "healthy"
},
"retryPolicy": {
"maxRetries": 2,
"initialDelayMs": 500
}
}

Example 5: File Upload

{
"url": "https://api.example.com/upload",
"method": "POST",
"authentication": {
"type": "ApiKey",
"credential": "api-key-here",
"keyName": "X-API-Key"
},
"body": {
"type": "Multipart",
"formData": {
"description": "Monthly report",
"category": "reports"
},
"files": [
{
"fieldName": "file",
"fileName": "report-2024-01.pdf",
"contentUrl": "https://internal.mycompany.com/reports/latest.pdf",
"contentType": "application/pdf"
}
]
}
}

Error Handling

The HTTP Worker distinguishes between permanent and transient errors:

Permanent Errors (No Retry)

These errors go directly to the Dead Letter Queue (DLQ):

ErrorDescription
HTTP 400Bad Request - Invalid request format
HTTP 401Unauthorized - Authentication failed
HTTP 403Forbidden - Access denied
HTTP 404Not Found - Resource doesn't exist
HTTP 405Method Not Allowed
HTTP 422Unprocessable Entity
Invalid Job DataMissing required fields, malformed JSON
Configuration ErrorsMissing OAuth2 TokenUrl, invalid certificate

Transient Errors (Retryable)

These errors are retried according to the retry policy:

ErrorDescription
HTTP 408Request Timeout
HTTP 429Too Many Requests (Rate Limited)
HTTP 500Internal Server Error
HTTP 502Bad Gateway
HTTP 503Service Unavailable
HTTP 504Gateway Timeout
Connection ErrorsNetwork failures, DNS resolution errors
TimeoutsRequest exceeded timeout

Job Result

After successful execution, the job stores a result summary:

{
"statusCode": 200,
"status": "OK",
"contentLength": 1234,
"body": "{\"success\": true, \"data\": {...}}"
}

Note: Response bodies larger than 2000 characters are truncated in the result.

Deployment

The HTTP Worker is included in the Milvaion distribution and can be deployed as a Docker container:

# docker-compose.yml
services:
http-worker:
image: milvasoft/milvaion-httpworker:latest
environment:
- Milvaion__WorkerId=http-worker
- Milvaion__DisplayName=HTTP Worker
- Milvaion__RabbitMQ__Host=rabbitmq
- Milvaion__RabbitMQ__Port=5672
- Milvaion__RabbitMQ__Username=guest
- Milvaion__RabbitMQ__Password=guest
- Milvaion__MaxParallelJobs=10

Best Practices

  1. Use Environment Variables for Secrets

    • Store API keys, tokens, and passwords in environment variables
    • Reference them in job data using variable substitution (if supported)
  2. Set Appropriate Timeouts

    • Match timeout to expected response time
    • Consider network latency for external APIs
  3. Configure Retry Policies

    • Set reasonable retry counts (3-5 is usually sufficient)
    • Use exponential backoff to avoid overwhelming services
  4. Validate Responses

    • Always validate expected status codes
    • Use JSONPath to verify response structure
  5. Monitor Execution

    • Check execution logs for debugging
    • Set up alerts for repeated failures

Coming Soon

Future built-in workers planned for Milvaion:

  • Email Worker - Send emails via SMTP or email service providers
  • Database Worker - Execute SQL queries and stored procedures
  • File Worker - File operations (copy, move, compress, upload to cloud storage)
  • Message Queue Worker - Send messages to other queues (Kafka, Azure Service Bus)

For custom workers, see Your First Worker and Implementing Jobs.