ReferenceDriverHTTPRead Task

HTTP Read Task

Learn how to acquire data from HTTP endpoints with Synnax.

For the task lifecycle, see Task Basics.

Task Configuration Reference

ParameterTypeRequiredDefaultDescription
devicestringYes-Key of the HTTP server device
ratenumberNo1Polling rate (Hz)
endpointsarrayYes-List of endpoint configurations

Endpoint Configuration Reference

Each endpoint defines an HTTP request to poll and a set of fields to extract from its JSON response.

ParameterTypeRequiredDefaultDescription
methodstringNo"GET"HTTP method
pathstringYes-URL path relative to the device base URL (e.g., /api/v1/data)
headersarrayNo-Additional request headers as {name, value} pairs
query_paramsarrayNo-Query parameters as {parameter, value} pairs
bodystringNo-Request body (for POST or other methods that accept a body)
indexstringNo-Key of the field whose channel indexes the others. Empty stamps samples on arrival
fieldsarrayYes-Fields to extract from the response

Field Extraction Reference

Fields define how to extract values from a JSON response body using JSON Pointers (RFC 6901). Each field maps a location in the response to a Synnax channel.

For example, given this response:

{ "temperature": 23.5, "sensors": { "pressure": 101.3 } }

A pointer of /temperature extracts 23.5, and /sensors/pressure extracts 101.3.

ParameterTypeRequiredDefaultDescription
pointerstringYes-JSON Pointer path to the value (e.g., /temperature)
channelnumberYes-Synnax channel key to write the extracted value to
data_typestringNo"float64"Data type of the channel
namestringNo-Human-readable name for the field
disabledbooleanNofalseExcludes the field from polling
time_formatstringNo-Timestamp format (required when the channel data type is TIMESTAMP)
enum_valuesarrayNo-String-to-number mapping for enum fields (e.g., [{"label": "OFF", "value": 0}, {"label": "ON", "value": 1}])

Enum Values

When the HTTP response contains string values that represent discrete states, use enum_values to map them to numbers. The Driver converts matching strings to their numeric equivalents before writing to the channel.

http.ReadField(
    pointer="/status",
    channel=status_ch.key,
    data_type="float64",
    enum_values=[{"label": "OFF", "value": 0}, {"label": "ON", "value": 1}, {"label": "ERROR", "value": 2}],
)

If the response value does not match any key in the map, the Driver reports an error.

Timestamp Handling

By default, the Driver automatically generates timestamps for each poll cycle using software timing. If your HTTP response includes a timestamp field, you can extract it directly by setting time_format on a field whose channel data type is TIMESTAMP.

Supported Timestamp Formats

FormatDescriptionExample
iso8601ISO 8601 date-time string"2024-01-15T10:30:00.000Z"
unix_secSeconds since Unix epoch1705312200
unix_msMilliseconds since Unix epoch1705312200000
unix_usMicroseconds since Unix epoch1705312200000000
unix_nsNanoseconds since Unix epoch1705312200000000000

Software vs. Hardware Timing

Software timing (default): The Driver generates a timestamp at each poll cycle. All fields that share the same index channel are written atomically. No time_format is needed on any field.

Hardware timing: If your response includes a timestamp, create a TIMESTAMP channel as the index and add a field that extracts it with a time_format. Other fields using that index channel will be grouped with the extracted timestamp.

How-To