Documentation Index
Fetch the complete documentation index at: https://platform.docs.zenoo.com/llms.txt
Use this file to discover all available pages before exploring further.
HTTP Connector Overview
The HTTP connector enables you to make HTTP(S) requests directly from the DSL, supporting a wide range of features for integration, automation, and external API communication.Related Connector DocumentationThe HTTP connector can be used standalone for direct response handling or within an exchange for unified error handling and retries. Below is a summary of its main features:
- Connectors Overview - Complete guide to Hub’s connector system
- Custom Connector Development - Build your own connectors
- Plugin Connector Development - OSGI plugin connectors
- Named HTTP Connectors: Assign names for better logging, metrics, and troubleshooting.
- Error Handling and Status Codes: Fine-grained control over retries and response handling, including Retries and response handlers.
- GET and POST Requests: Simple syntax for common HTTP methods.
- Query Parameters: Easily add dynamic query parameters with proper encoding.
- Headers: Add custom HTTP headers for authentication, API keys, and more.
- Request Body Types: Support for JSON, raw, form, multipart, and JWT bodies.
- Authorization: Built-in support for Basic and Bearer authentication.
- Transports: Reusable authentication and base URL configuration (Basic, Bearer/OAuth2, etc.).
- Best Practices: Tips for robust and maintainable integrations.
HTTP connector
A built-in HTTP connector facilitates making HTTP calls directly from the DSL. It is possible to reference and use context attributes in a connector definition. The common use-cases include URL and body generation, authentication headers, etc. An HTTP connector response is automatically converted into a context attribute based on the content type. There is a built-in support for JSON and XML content types.Usage Patterns
Standalone HTTP Usage
Use HTTP directly when you need granular control over response handling, such as branching logic based on specific status codes:Exchange-wrapped HTTP Usage
Use HTTP within an exchange for unified error handling, retries, and monitoring:- Need different handling for specific status codes (400, 401, 404, etc.)
- Complex response branching logic
- Custom retry strategies per status code
- Immediate response processing without standard error wrapping
- Standard error handling and retries are sufficient
- Want consistent monitoring and metrics
- Need timeout configuration
- Prefer unified connector interface
Named HTTP Connectors
You can assign a name to an HTTP connector invocation using the syntax:Why use a name?
- Logging: Named HTTP connectors make logs more readable and easier to search, as the name appears in execution logs.
- Metrics: Names are used as identifiers in metrics, making it easier to track the performance and usage of specific API calls.
- Troubleshooting: When errors occur, having a descriptive name helps quickly identify which external call failed.
- Billing: If you track API usage for billing or cost allocation, using names allows for more granular reporting.
Default Name
If you do not provide a name, the connector will use the request URL as the default name in logs and metrics:url property.
Tip: Use descriptive names for important or frequently used HTTP connectors to improve observability and maintainability.
Error Handling and Status Codes
The HTTP connector provides several ways to handle responses and errors:Response Handlers
You can use response handlers to manage different outcomes of your HTTP requests:- onStatus(statusCode): Executes a block if the response status code matches the given value. Useful for handling specific error or success codes.
- onStatus([statusCode1, statusCode2, …]): Executes a block if the response status code matches any of the values in the array. Useful for handling multiple related status codes.
- onStatus(range): Executes a block if the response status code falls within the given range (e.g.,
400..499for client errors,500..599for server errors). - onResponse: Executes a block for any response, giving you access to the full response entity (headers, status, payload).
- onSuccess: Executes a block if the request is successful (typically for 2xx status codes).
- onError: Executes a block if the request results in an error (typically for 4xx or 5xx status codes).
GET requests
Making an HTTP GET is as simple as providing a request urlQuery Parameters
Query parameters can be added to HTTP requests using the queryParam method. This is particularly useful when you need to:- Add dynamic parameters from context attributes
- Maintain clean, readable URL construction
- Properly encode parameter values
Note: Query parameters are automatically URL-encoded unless you use disabledEncoding(). See URL Encoding for more details.
Headers
The header method allows you to add custom HTTP headers to your request. Headers are commonly used for:- Custom authentication tokens
- API keys
- Content negotiation
- Tracking and correlation IDs
Tip: For standard authentication, use the dedicated methods:basicAuthfor Basic authentication (see Authorization) orbearerAuthfor Bearer tokens instead of setting headers manually.
Note: Headers can also be configured at the transport level for reuse across multiple requests. Connector-level headers override transport-level headers with the same name.
POST requests
HTTP POST request has the method set toPOST.
JSON body
The request body is set using the payload expression result. The payload expression can reference and use available context attributes. Retryable error forces connector to try again even on 404 NOT_FOUND response from server. This can be useful in subsequent call to easily poll for object until it is ready.application/json content type.
JSON body with Base64-encoded files
It is possible to specify a JSON request body using descriptors. The corresponding files are encoded using Base64.HTTP body with binary data
Some API endpoints require sending binary data in HTTP body. This is supported by rawBody. You can send content of a file by passing a file descriptor to it. If the parameter is a string, it’s send as it is, maps and lists are rendered as json.Form data
The formData specifies an HTTP request using a form data usingapplication/x-www-form-urlencoded content type.
Multipart data
The HTTP connector supports sendingmultipart/form-data requests with various content types using the following methods:
multipartFile(String name, Attribute descriptor): Adds a file part to the request. Thedescriptorshould be anAttributethat represents aFileDescriptor. The content type is set according to the provided file descriptor.multipartText(String name, String content): Adds a text part to the request. The content type is automatically set totext/plain.multipartJson(String name, Object content): Adds a JSON part to the request. Thecontentcan be anAttributeor any object that can be serialized to JSON (e.g., a map, a list, or a custom object). The content type is automatically set toapplication/json.multiPart(String name, String contentType, Object value): Adds a multipart entry with the specified content type. ThecontentTypeshould be one of the following:file(application/octet-stream),text(text/plain), orjson(application/json).
multipartFile:
multipartText:
multipartJson:
JWT in body
The request body is specified using jwtBody. The payload expression can reference and use available context attributes. In addition to payload it necessary to define secret which is a shared secret with the other service. alg is optional and defaults toHS256. Possible values are “HS256”, “HS384” and “HS512"".
JWT body with Base64-encoded files
It is possible to specify a JWT request body using descriptors. The corresponding files are encoded using Base64.Request method
The method specifies an HTTP request method. If omitted, the default method is GET. The method can be one of the following:DELETEGETHEADOPTIONSPATCHPOSTPUTTRACE
Content type
The contentType specifies an HTTP requestContent-Type header.
URL Encoding
Disable URL encoding in the request to avoid double encoding.Retries
By default, the HTTP connector will automatically retry requests for the following status codes:- 408 (Request Timeout)
- 425 (Too Early)
- 429 (Too Many Requests)
- 500 (Internal Server Error)
- 502 (Bad Gateway)
- 503 (Service Unavailable)
- 504 (Gateway Timeout)
retryableError and unretryableError options:
- Use
retryableError <code>to add a status code to the retryable list. - Use
unretryableError <code>to remove a status code from the retryable list.
Authorization
Basic authentication
The basicAuth specifies an HTTP basic authentication credentials.Bearer authentication
The bearerAuth specifies a Bearer Authentication token used inAuthentication HTTP header. unretryableError makes
connector not to retry the request on specified response status code which might become handy if there’s non-standard server/gateway behaviour.
Transports
A transport is a reusable configuration for HTTP connections, allowing you to define a base URL and authentication method (such as Basic or Bearer/OAuth2). You can reference a transport by name in your HTTP connector, making it easy to share connection settings across multiple requests.Defining a Transport
Transports are defined separately and can include a base URL and authentication. Example definitions: Basic Authentication Transport:Note:
- The
urlcan be relative to the transport’sbaseUrl- The authentication method defined in the transport will be applied automatically
- You can use context attributes in transport definitions for dynamic configuration
- The default grant type for bearer is
passwordif not specified- Transport headers are applied as default headers to all requests using that transport
- Headers can be defined using single values, lists, or map syntax
- Connector-level headers override transport-level headers with the same name
Using a Transport in HTTP Connector
To use a transport, reference it by name in your HTTP connector:Best Practices
-
Error Handling:
- Always handle expected error cases using
onStatushandlers - Use
retryableErrorandunretryableErrorto customize retry behavior - Consider using transports for consistent error handling across multiple requests
- Always handle expected error cases using
-
Authentication:
- Use transports for reusable authentication configurations
- Keep sensitive credentials in context attributes or secure storage
- Consider token expiration and refresh mechanisms for OAuth2
-
Request Configuration:
- Use context attributes for dynamic URLs and parameters
- Set appropriate timeouts for different types of requests
- Use appropriate content types for different body types
-
File Handling:
- Use appropriate multipart methods for file uploads
- Consider file size limits and content types
- Use Base64 encoding when required by the API
-
Response Handling:
- Use appropriate response handlers for different status codes
- Handle both success and error cases
- Consider response size and content type