HTTP data sources
EXTERNAL_HTTP() lets FeatureQL fetch data from REST APIs, microservices, and any HTTP endpoint. This is useful for integrating third-party services, calling internal microservices, or querying ML model endpoints as part of a feature computation.
Creating an HTTP source
Define a reusable HTTP endpoint with SOURCE_HTTP():
CREATE OR REPLACE FEATURE FM.TUTORIALS.EXTERNAL_HTTP.HTTP_SOURCE AS
SOURCE_HTTP(
'http://host.docker.internal:18010/hello'
WITH (
query_params=ROW('default' AS "name"),
timeout='500ms'
)
);| feature_name VARCHAR | status VARCHAR | message VARCHAR |
|---|---|---|
| FM.TUTORIALS.EXTERNAL_HTTP.HTTP_SOURCE | CREATED | Feature created as not exists |
The source captures the base URL, default query parameters, and timeout. These defaults apply to every request unless overridden at call time.
Install the source synchronously in a local development serving process:
RECOMPILE SERVING;| FEATURE VARCHAR | KIND VARCHAR | STATUS VARCHAR | MESSAGE VARCHAR | SINCE VARCHAR |
|---|---|---|---|---|
| FM.TUTORIALS.EXTERNAL_HTTP.HTTP_SOURCE | SOURCE_HTTP | LOADED |
Making requests with EXTERNAL_HTTP()
Use EXTERNAL_HTTP() to call the endpoint with dynamic parameters:
DEFINE
firstname := INPUT(VARCHAR)
RETURN
firstname,
http_response := EXTERNAL_HTTP(
FROM fm.tutorials.external_http.http_source
WITH (
QUERY_PARAMS = ROW(firstname AS name)
)
)[value]
FOR
firstname := BIND_VALUES(ARRAY('Alice', 'Bob', 'Charlie'))
;| FIRSTNAME VARCHAR | HTTP_RESPONSE VARCHAR |
|---|---|
| Alice | Hello Alice! |
| Bob | Hello Bob! |
| Charlie | Hello Charlie! |
The query_params in the request override the defaults from the source definition. For each input value, FeatureMesh issues a separate HTTP request — FIRSTNAME := 'Alice' becomes GET http://host.docker.internal:18010/hello?name=Alice, and so on.
EXTERNAL_HTTP() returns a ROW(value JSON): read the answer with [value], and parse structured responses with JSON_PARSE_AS() to get a typed row. If a request fails (timeout, network error, non-2xx response), the query fails with that error: a missing answer is never turned into NULL silently. To handle failures instead, read the row's source_status (OK, MISS, TIMEOUT, UNAVAILABLE or ERROR): it guards the read, so on a failed request the value is NULL, the status says why, and the call succeeds ( Errors and fallbacks ).
What goes where
Every property can be set on the source, as a default for all calls, or on the call, from the row's values:
| Property | On the source | On the call |
|---|---|---|
method | Default method ('GET' if none) | Replaces it |
path | Appended to the base URL | Resolved against the base URL: '/v1/risk' replaces its path, 'risk' is relative to it |
headers | ROW of VARCHAR: sent with every call | Added to the source's |
query_params | ROW of VARCHAR | Override the source's by name, the others kept |
body | Sent by calls that give none: ROW as a JSON object, VARCHAR as is | Replaces the source's: ROW sent as a JSON object, or a VARCHAR sent as is |
timeout | Per request, such as '500ms' | Replaces the source's for this call |
Query parameters and header values are text in HTTP, so they must be VARCHAR: cast numbers with ::VARCHAR. A number is refused rather than dropped:
RETURN
greeting := EXTERNAL_HTTP(
FROM fm.tutorials.external_http.http_source
WITH (
QUERY_PARAMS = ROW(42 AS name)
)
)
;Sending a JSON body
Most APIs that take more than a name or two take a POST with a JSON body. Here a fraud-risk API expects:
{
"model": "fraud-v4",
"customer": {"id": 11, "country": "FR", "account_age_days": 12},
"order": {"amount": 800.0, "country": "US"}
} and answers {"model": "fraud-v4", "score": 1.0, "reasons": ["large_amount", ...]}. The source holds what every call shares: the method, the path and a version header.
CREATE OR REPLACE FEATURE FM.TUTORIALS.EXTERNAL_HTTP.RISK_API AS
SOURCE_HTTP(
'http://host.docker.internal:18010'
WITH (
method = 'POST',
path = '/v1/risk',
headers = ROW('2' AS "x-api-version"),
timeout = '500ms'
)
);| feature_name VARCHAR | status VARCHAR | message VARCHAR |
|---|---|---|
| FM.TUTORIALS.EXTERNAL_HTTP.RISK_API | CREATED | Feature created as not exists |
The feature describes the call. The body is a ROW whose shape is the JSON object: each AS names a field, a nested ROW is a nested object, an ARRAY a JSON array, and a constant such as the model name is just a value. Names that are FeatureQL keywords, such as order, are quoted. JSON_PARSE_AS() types the answer:
CREATE OR REPLACE FEATURES IN FM.TUTORIALS.EXTERNAL_HTTP AS
PERSIST
ORDER_ID := INPUT(BIGINT),
CUSTOMER_ID := INPUT(BIGINT),
CUSTOMER_COUNTRY := INPUT(VARCHAR),
ACCOUNT_AGE_DAYS := INPUT(BIGINT),
AMOUNT := INPUT(DOUBLE),
ORDER_COUNTRY := INPUT(VARCHAR),
ORDER_RISK := JSON_PARSE_AS(
EXTERNAL_HTTP(
FROM RISK_API
WITH (body = ROW(
'fraud-v4' AS model,
ROW(CUSTOMER_ID AS id, CUSTOMER_COUNTRY AS country, ACCOUNT_AGE_DAYS AS account_age_days) AS customer,
ROW(AMOUNT AS amount, ORDER_COUNTRY AS country) AS "order"
))
)[value] AS ROW(model VARCHAR, score DOUBLE, reasons ARRAY(VARCHAR))
);| feature_name VARCHAR | status VARCHAR | message VARCHAR |
|---|---|---|
| FM.TUTORIALS.EXTERNAL_HTTP.ACCOUNT_AGE_DAYS | CREATED | Feature created as not exists |
| FM.TUTORIALS.EXTERNAL_HTTP.AMOUNT | CREATED | Feature created as not exists |
| FM.TUTORIALS.EXTERNAL_HTTP.CUSTOMER_COUNTRY | CREATED | Feature created as not exists |
| FM.TUTORIALS.EXTERNAL_HTTP.CUSTOMER_ID | CREATED | Feature created as not exists |
| FM.TUTORIALS.EXTERNAL_HTTP.ORDER_COUNTRY | CREATED | Feature created as not exists |
| FM.TUTORIALS.EXTERNAL_HTTP.ORDER_ID | CREATED | Feature created as not exists |
| FM.TUTORIALS.EXTERNAL_HTTP.ORDER_RISK | CREATED | Feature created as not exists |
Six inputs describe an order. A query binds them together, one row per order, and FeatureMesh sends one POST per row:
RETURN
fm.tutorials.external_http.order_id,
model := fm.tutorials.external_http.order_risk[model],
score := fm.tutorials.external_http.order_risk[score],
reasons := fm.tutorials.external_http.order_risk[reasons]
FOR
(fm.tutorials.external_http.order_id, fm.tutorials.external_http.customer_id, fm.tutorials.external_http.customer_country, fm.tutorials.external_http.account_age_days, fm.tutorials.external_http.amount, fm.tutorials.external_http.order_country) := BIND_VALUES(
ARRAY(
ROW(1, 10, 'FR', 400, 20.0e0, 'FR'),
ROW(2, 11, 'FR', 12, 800.0e0, 'US')
)
)
;| ORDER_ID BIGINT | MODEL VARCHAR | SCORE DOUBLE | REASONS VARBINARY |
|---|---|---|---|
| 1 | fraud-v4 | 0.1 | [] |
| 2 | fraud-v4 | 1.0 | [large_amount, foreign_country, new_account] |
From a prepared statement
In production, the caller sends the orders and nothing else. Group the six inputs in USING, so that they form one input table:
CREATE OR REPLACE FEATURE FM.TUTORIALS.EXTERNAL_HTTP.ORDER_RISK_PS AS
PREPARED_STATEMENT(
FM.TUTORIALS.EXTERNAL_HTTP.ORDER_RISK
USING (
FM.TUTORIALS.EXTERNAL_HTTP.ORDER_ID,
FM.TUTORIALS.EXTERNAL_HTTP.CUSTOMER_ID,
FM.TUTORIALS.EXTERNAL_HTTP.CUSTOMER_COUNTRY,
FM.TUTORIALS.EXTERNAL_HTTP.ACCOUNT_AGE_DAYS,
FM.TUTORIALS.EXTERNAL_HTTP.AMOUNT,
FM.TUTORIALS.EXTERNAL_HTTP.ORDER_COUNTRY
)
);| feature_name VARCHAR | status VARCHAR | message VARCHAR |
|---|---|---|
| FM.TUTORIALS.EXTERNAL_HTTP.ORDER_RISK_PS | CREATED | Feature created as not exists |
Each row of input_1 lists one order's values in the order of USING:
FM.TUTORIALS.EXTERNAL_HTTP.ORDER_RISK_PS{"input_1": [[1, 10, "FR", 400, 20.0, "FR"], [3, 12, "DE", 90, 650.0, "DE"]]} | ORDER_ID BIGINT | CUSTOMER_ID BIGINT | CUSTOMER_COUNTRY VARCHAR | ACCOUNT_AGE_DAYS BIGINT | AMOUNT DOUBLE | ORDER_COUNTRY VARCHAR | ORDER_RISK_PS ROW |
|---|---|---|---|---|---|---|
| 1 | 10 | FR | 400 | 20.0 | FR | {model: fraud-v4, score: 0.1, reasons: []} |
| 3 | 12 | DE | 90 | 650.0 | DE | {model: fraud-v4, score: 0.4, reasons: [large_amount]} |
The same call with curl:
curl -X POST "http://localhost:10090/v1/featureql" \
-H "Content-Type: application/json" \
-d '{
"statement": {
"id": "FM.TUTORIALS.EXTERNAL_HTTP.ORDER_RISK_PS",
"inputs": {
"input_1": [
[1, 10, "FR", 400, 20.0, "FR"],
[3, 12, "DE", 90, 650.0, "DE"]
]
}
}
}' Listing the inputs separately, USING (ORDER_ID), (CUSTOMER_ID), ..., would make six input tables combined by cross product: right for independent inputs, wrong for the fields of one order.
Several rows per call
One request per input row is fine for a few rows, but an endpoint that scores a list — a model server ranking 200 candidates, a bulk lookup API — should get the rows in one call. The source's batch property sends up to size rows per request:
CREATE OR REPLACE FEATURE FM.TUTORIALS.EXTERNAL_HTTP.HELLO_MODEL AS
SOURCE_HTTP(
'http://host.docker.internal:18010/v1/models/hello:predict'
WITH (
method='POST',
batch=ROW(64 AS size),
timeout='500ms'
)
);| feature_name VARCHAR | status VARCHAR | message VARCHAR |
|---|---|---|
| FM.TUTORIALS.EXTERNAL_HTTP.HELLO_MODEL | CREATED | Feature created as not exists |
DEFINE
firstname := INPUT(VARCHAR)
RETURN
firstname,
greeting := EXTERNAL_HTTP(
FROM fm.tutorials.external_http.hello_model
WITH (
BODY = ROW(firstname AS name)
)
)[value]
FOR
firstname := BIND_VALUES(ARRAY('Alice', 'Bob', 'Charlie'))
;| FIRSTNAME VARCHAR | GREETING VARCHAR |
|---|---|
| Alice | Hello Alice! |
| Bob | Hello Bob! |
| Charlie | Hello Charlie! |
The rows that share method, URL and headers go together: each row's JSON body becomes one element of an array, and the answer must hold one result per row in an array, in the same order — position matches a result to its row. A result that is a JSON string comes back as its text, any other value as JSON, and null as NULL. An answer without exactly one result per row fails the query.
Where the arrays sit depends on the endpoint:
| Property | Default | Meaning |
|---|---|---|
size | required | Rows per call at most |
request_field | 'instances' | Field of the request object holding the rows' bodies; '' sends the bare array |
response_field | 'predictions' | Field (or dotted path, such as 'data.scores') of the answer holding the results; '' when the answer is the bare array |
The defaults are the KServe v1 / TF Serving prediction protocol, {"instances": [...]} in and {"predictions": [...]} out, which most model servers speak. With request_field='', response_field='', the source posts [body, ...] and reads [result, ...].
A batch endpoint of your own
The risk API above also has a batch endpoint, with its own field names: it takes {"rows": [body, ...]} and answers {"data": {"scores": [result, ...]}}. The source says so:
CREATE OR REPLACE FEATURE FM.TUTORIALS.EXTERNAL_HTTP.RISK_BATCH_API AS
SOURCE_HTTP(
'http://host.docker.internal:18010/v1/risk:batch'
WITH (
method = 'POST',
batch = ROW(100 AS size, 'rows' AS request_field, 'data.scores' AS response_field),
timeout = '500ms'
)
);| feature_name VARCHAR | status VARCHAR | message VARCHAR |
|---|---|---|
| FM.TUTORIALS.EXTERNAL_HTTP.RISK_BATCH_API | CREATED | Feature created as not exists |
The feature is written exactly as for one row per call: the same nested body, the same JSON_PARSE_AS() of one result. Only the source changes, and the three orders go in one POST:
DEFINE
order_risk_batch := JSON_PARSE_AS(
EXTERNAL_HTTP(
FROM fm.tutorials.external_http.risk_batch_api
WITH (
BODY = ROW(
ROW(
fm.tutorials.external_http.customer_id AS id,
fm.tutorials.external_http.customer_country AS country,
fm.tutorials.external_http.account_age_days AS account_age_days
) AS customer,
ROW(
fm.tutorials.external_http.amount AS amount,
fm.tutorials.external_http.order_country AS country
) AS order
)
)
)[value] AS ROW<score DOUBLE, reasons ARRAY<VARCHAR>>
)
RETURN
fm.tutorials.external_http.order_id,
score := order_risk_batch[score],
reasons := order_risk_batch[reasons]
FOR
(fm.tutorials.external_http.order_id, fm.tutorials.external_http.customer_id, fm.tutorials.external_http.customer_country, fm.tutorials.external_http.account_age_days, fm.tutorials.external_http.amount, fm.tutorials.external_http.order_country) := BIND_VALUES(
ARRAY(
ROW(1, 10, 'FR', 400, 20.0e0, 'FR'),
ROW(2, 11, 'FR', 12, 800.0e0, 'US'),
ROW(3, 12, 'DE', 90, 650.0e0, 'DE')
)
)
;| ORDER_ID BIGINT | SCORE DOUBLE | REASONS VARBINARY |
|---|---|---|
| 1 | 0.1 | [] |
| 2 | 1.0 | [large_amount, foreign_country, new_account] |
| 3 | 0.4 | [large_amount] |
Moving a feature from per-row calls to batches is a change of source, not of the feature.
Authenticated calls
Put the token in the source's headers, read with SECRET() from the serving engine's environment or a mounted file, so the registry never holds it:
SCORING_API := SOURCE_HTTP(
'https://scoring.internal/v1/score'
WITH (
method = 'POST',
headers = ROW('Bearer ' || SECRET('env', 'SCORING_API_TOKEN') AS "Authorization"),
timeout = '200ms'
)
)
When a rotated token applies, and what an unset variable does, is in Credentials .
Performance considerations
Parallelization: FeatureMesh issues the requests of a query concurrently, up to 32 at a time, whether each carries one row or a batch.
Batching: When the endpoint accepts lists, set batch on the source. 200 rows become one or a few calls instead of 200.
No retries: There is no built-in retry policy. If reliability is critical, put a retry-capable proxy or load balancer in front of the target service.
Related
- Choosing a pattern : when an HTTP source fits, and when a database or Redis is the better read.
- Prepare the stores : timeouts and rate limits.