搜索快捷键 cmd + k | ctrl + k
http_client

DuckDB HTTP 客户端扩展

安装和加载

INSTALL http_client FROM community;
LOAD http_client;

示例

-- 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 
└────────┴─────────┴─────────────┘

关于 http_client

HTTP 客户端扩展是实验性的,使用风险自负!

新增函数

函数名 函数类型 描述 注释 示例
http_get 标量 NULL NULL  
http_post 标量 NULL NULL  
http_post_form 标量 NULL NULL