Search Shortcut cmd + k | ctrl + k
http_client

DuckDB HTTP Client Extension

Installing and Loading

INSTALL http_client FROM community;
LOAD http_client;

Example

-- GET Request Example w/ JSON Parsing
WITH __input AS (
  SELECT
    http_get(
        'https://httpbin.org/delay/0',
        headers => MAP {
          'accept': 'application/json',
        },
        params => MAP {
          'limit': 1
        }
    ) AS res
),
__response AS (
  SELECT
    (res->>'status')::INT AS status,
    (res->>'reason') AS reason,
    unnest( from_json(((res->>'body')::JSON)->'headers', '{"Host": "VARCHAR"}') ) AS features
  FROM
    __input
)
SELECT
  __response.status,
  __response.reason,
  __response.Host AS host
FROM
  __response
;
┌────────┬─────────┬─────────────┐
 status  reason      host     
 int32   varchar    varchar   
├────────┼─────────┼─────────────┤
    200  OK       httpbin.org 
└────────┴─────────┴─────────────┘

-- POST Request Example w/ Headers and Parameters
WITH __input AS (
SELECT
  http_post(
      'https://httpbin.org/delay/0',
      headers => MAP {
        'accept': 'application/json',
      },
      params => MAP {
        'limit': 1
      }
  ) AS res
),
__response AS (
  SELECT
    (res->>'status')::INT AS status,
    (res->>'reason') AS reason,
    unnest( from_json(((res->>'body')::JSON)->'headers', '{"Host": "VARCHAR"}') ) AS features
  FROM
    __input
)
SELECT
  __response.status,
  __response.reason,
  __response.Host AS host,
FROM
  __response
;
┌────────┬─────────┬─────────────┐
 status  reason      host     
 int32   varchar    varchar   
├────────┼─────────┼─────────────┤
    200  OK       httpbin.org 
└────────┴─────────┴─────────────┘

About http_client

The HTTP Client Extension is experimental, use at your own risk!

Added Functions

function_name function_type description comment example
http_get scalar      
http_post scalar