DuckDB HTTP API 服务器扩展
安装和加载
INSTALL httpserver FROM community;
LOAD httpserver;
示例
-- Start a DuckDB HTTP API Server with parameters
D SELECT httpserve_start('0.0.0.0', 9999, 'user:pass');
┌───────────────────────────────────────────────┐
│ httpserve_start('0.0.0.0', 9999, 'user:pass') │
│ varchar │
├───────────────────────────────────────────────┤
│ HTTP server started on 0.0.0.0:9999 │
└───────────────────────────────────────────────┘
-- Browse to your DuckDB HTTP API endpoint to Query using the embedded interface
-- Query your DuckDB HTTP API Server using curl or any other client w/ HTTP Basic Auth
curl -X POST -d "LOAD chsql; SELECT *, uuid() FROM numbers(10)" "http://user:pass@localhost:9999/"
-- Query your DuckDB HTTP API Server using curl or any other client w/ X-API-Key header
curl -X POST --header "X-API-Key: secretkey" -d "LOAD chsql; SELECT *, uuid() FROM numbers(10)" "https://:9999/"
-- Query your DuckDB HTTP API Server using DuckDB HTTPFS extension w/ Header Authentication
D CREATE SECRET extra_http_headers (
TYPE HTTP,
EXTRA_HTTP_HEADERS MAP{
'X-API-Key': 'secretkey'
}
);
-- DuckDB API Server settings
* If you want no authentication, just pass an empty string as parameter.
* If you want the API run in foreground set `DUCKDB_HTTPSERVER_FOREGROUND=1`
* If you want logs set `DUCKDB_HTTPSERVER_DEBUG=1` or `DUCKDB_HTTPSERVER_SYSLOG=1`

关于 httpserver
DuckDB HTTP 服务器扩展
此扩展将 DuckDB 实例转换为轻量级多用户 HTTP OLAP API 服务。
支持认证 (基本认证或 X-Token) 并包含 play SQL 用户界面。
功能
- 将任何 DuckDB 实例转换为 HTTP OLAP API 服务器
- 使用内置的 Web 用户界面 来查询和可视化数据
- 使用本地和远程数据集,包括 MotherDuck 🐤
- 100% 开源,可供社区随时使用和扩展!
此扩展为实验性质,可能不稳定。请自行承担风险使用。
新增函数
函数名称 | 函数类型 | 描述 | 备注 | 示例 |
---|---|---|---|---|
httpserve_start | 标量 | NULL | NULL | |
httpserve_stop | 标量 | NULL | NULL |