HTTP APIs (Ivan - need review)
CrateDB allows data ingestion from various sources, including HTTP APIs. This can be done by sending data in JSON format to the HTTP endpoint. Only JSON is supported.
To leverage bulk ingestion the HTTP endpoint has a bulk_args
parameter that accepts a list of rows, every value is binded to a placeholder character: ?
Below are examples of how to ingest data using curl and Python.
Ingesting Data Using curl
To ingest data using curl
, send a POST request to the HTTP endpoint with the appropriate JSON payload.
curl -sS -H 'Content-Type: application/json' \
-X POST '127.0.0.1:4200/_sql' \
-d '{
"stmt": "INSERT INTO metrics (ts, location, temperature, humidity, cpu_load, battery_level) VALUES (?, ?, ?, ?, ?, ?)",
"bulk_args": [
["2025-08-11T10:00:00Z", "Greenhouse-1", 24.5, 60.2, 12.5, 89.0],
["2025-08-11T10:00:05Z", "Factory-Floor", 28.1, 45.7, 54.8, 65.3],
["2025-08-11T10:00:10Z", "Server-Room", 21.9, 40.0, 75.2, 100.0]
]
}'
Ingesting Data Using Python
import requests
import datetime
url = "http://192.168.88.251:4200/_sql"
payload = {
"stmt": """
INSERT INTO metrics (ts, location, temperature, humidity, cpu_load, battery_level)
VALUES (?, ?, ?, ?, ?, ?)
""",
"bulk_args": [
[datetime.datetime.now().isoformat(), "Greenhouse-1", 24.5, 60.2, 12.5, 89.0],
[datetime.datetime.now().isoformat(), "Factory-Floor", 28.1, 45.7, 54.8, 65.3],
[datetime.datetime.now().isoformat(), "Server-Room", 21.9, 40.0, 75.2, 100.0]
]
}
response = requests.post(url, json=payload)
Last updated