http_client
DuckDB Extension
An experimental extension that allows DuckDB to send HTTP GET/POST requests.
Installation
http_client
is a DuckDB Community Extension.
You can install and use this extension with the following SQL commands:
FROM community;
INSTALL http_client LOAD http_client;
For more information about DuckDB extensions, see the official documentation.
Functions
http_get(url)
http_post(url, headers, params)
- Sends POST request with params encoded as a JSON object
http_post_form(url, headers, params)
- Sends POST request with params being
application/x-www-form-urlencoded
encoded (used by many forms and some APIs)
- Sends POST request with params being
Examples
GET
WITH __input AS (
D SELECT
http_get('https://httpbin.org/delay/0'
AS res
)
),AS (
__response SELECT
->>'status')::INT AS status,
(res->>'reason') AS reason,
(res->>'body')::JSON)->'headers', '{"Host": "VARCHAR"}') ) AS features
unnest( from_json(((resFROM
__input
)SELECT
__response.status,
__response.reason,AS host,
__response.Host FROM
__response
;
┌────────┬─────────┬─────────────┐
│ status │ reason │ host │varchar │ varchar │
│ int32 │
├────────┼─────────┼─────────────┤200 │ OK │ httpbin.org │
│ └────────┴─────────┴─────────────┘
POST
WITH __input AS (
D SELECT
http_post('https://httpbin.org/delay/0',
=> MAP {
headers 'accept': 'application/json',
},=> MAP {
params
}AS res
)
),AS (
__response SELECT
->>'status')::INT AS status,
(res->>'reason') AS reason,
(res->>'body')::JSON)->'headers', '{"Host": "VARCHAR"}') ) AS features
unnest( from_json(((resFROM
__input
)SELECT
__response.status,
__response.reason,AS host,
__response.Host FROM
__response
;
┌────────┬─────────┬─────────────┐
│ status │ reason │ host │varchar │ varchar │
│ int32 │
├────────┼─────────┼─────────────┤200 │ OK │ httpbin.org │
│ └────────┴─────────┴─────────────┘
POST using form encoding(application/x-www-form-urlencoded, not multipart/form-data)
WITH __input AS (
D SELECT
http_post_form('https://httpbin.org/delay/0',
=> MAP {
headers 'accept': 'application/json',
},=> MAP {
params 'limit': 10
}AS res
)
),AS (
__response SELECT
->>'status')::INT AS status,
(res->>'reason') AS reason,
(res->>'body')::JSON)->'form', '{"limit": "VARCHAR"}') ) AS features
unnest( from_json(((resFROM
__input
)SELECT
__response.status,
__response.reason,limit AS limit
__response.FROM
__response
;
┌────────┬─────────┬─────────┐limit │
│ status │ reason │ varchar │ varchar │
│ int32 │
├────────┼─────────┼─────────┤200 │ OK │ 10 │
│ └────────┴─────────┴─────────┘
Full Example w/ spatial data
This is the original example by @ahuarte47 inspiring this community extension.
LOAD json;
LOAD httpfs;
LOAD spatial;
WITH __input AS (
SELECT
http_get('https://earth-search.aws.element84.com/v0/search')
AS res
),AS (
__features SELECT
->>'body')::JSON)->'features', '["json"]') )
unnest( from_json(((resAS features
FROM
__input
)SELECT
->>'id' AS id,
features->'properties'->>'sentinel:product_id' AS product_id,
featuresconcat(
'T',
->'properties'->>'sentinel:utm_zone',
features->'properties'->>'sentinel:latitude_band',
features->'properties'->>'sentinel:grid_square'
featuresAS grid_id,
) ->'geometry') AS geom
ST_GeomFromGeoJSON(featuresFROM
__features
;
┌──────────────────────┬──────────────────────┬─────────┬──────────────────────────────────────────────────────────────────────────────────┐id │ product_id │ grid_id │ geom │
│ varchar │ varchar │ varchar │ geometry │
│
├──────────────────────┼──────────────────────┼─────────┼──────────────────────────────────────────────────────────────────────────────────┤146.7963024570636 -42.53859799130381, 145.7818492341335 -42.53284395… │
│ S2B_55GDP_20241003… │ S2B_MSIL2A_2024100… │ T55GDP │ POLYGON ((146.9997932100229 -34.429312828654396, 146.9997955899612 -33.4390429… │
│ S2B_55HEC_20241003… │ S2B_MSIL2A_2024100… │ T55HEC │ POLYGON ((149.9810192714723 -25.374826158099584, 149.9573295859729 -24.3845516… │
│ S2B_55JHN_20241003… │ S2B_MSIL2A_2024100… │ T55JHN │ POLYGON ((-92.01266261624052 -2.357695714729873, -92.0560908879947 -2.35076658… │
│ S2B_15MWT_20230506… │ S2B_MSIL2A_2023050… │ T15MWT │ POLYGON ((-88.74518736203468 11.690012668805194, -88.9516536515512 11.72635252… │
│ S2B_16PBT_20230506… │ S2B_MSIL2A_2023050… │ T16PBT │ POLYGON ((-87.82703591176752 11.483638069337541, -88.8349824533826 11.70734355… │
│ S2B_16PCT_20230506… │ S2B_MSIL2A_2023050… │ T16PCT │ POLYGON ((-89.24113885498912 11.784951995968179, -89.38831685490888 11.8080246… │
│ S2B_15PZP_20230506… │ S2B_MSIL2A_2023050… │ T15PZP │ POLYGON ((-87.00017408768262 11.277451946475995, -87.00017438483464 11.7600349… │
│ S2B_16PET_20230506… │ S2B_MSIL2A_2023050… │ T16PET │ POLYGON ((-88.74518962519173 11.690373971442378, -89.62017907866615 11.8466519… │
│ S2B_16PBU_20230506… │ S2B_MSIL2A_2023050… │ T16PBU │ POLYGON ((-87.91783982214183 11.670141095427311, -87.92096676562824 12.5828090… │
│ S2B_16PDU_20230506… │ S2B_MSIL2A_2023050… │ T16PDU │ POLYGON ((
├──────────────────────┴──────────────────────┴─────────┴──────────────────────────────────────────────────────────────────────────────────┤10 rows 4 columns │
│ └──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
License
Love ❤️ this DuckDB extension? You’ll Love This.
Get the best from Query.Farm — smart tips, powerful tools, and project updates sent directly to your inbox, but only when we’ve got something great to share.