Skip to content

Server functions in the HTTP Server DuckDB extension

Function category

Server

2 functions

Start and stop the embedded HTTP query listener. The third argument to `httpserve_start` selects the auth mode — empty (no auth), `user:pass` (HTTP Basic), or any other value (shared key in `X-API-Key`).

httpserve_start

Scalar function Server
Signature
httpserve_start( host: VARCHAR, port: INTEGER, auth: VARCHAR ) VARCHAR
Arguments (Positional)
Argument host Type VARCHAR Mode Positional Description Interface to bind on. Use 'localhost' (or '127.0.0.1') to keep the server reachable only from the same machine. Use '0.0.0.0' to listen on all interfaces — only do this behind a firewall or reverse proxy.
Argument port Type INTEGER Mode Positional Description TCP port to listen on. Any unused port; 9999 is conventional in the upstream examples.
Argument auth Type VARCHAR Mode Positional Description Authentication selector. Empty string disables auth (development only). A value containing ':' is parsed as user:password and enables HTTP Basic auth. Any other value is treated as a single shared key the client must send in the X-API-Key header. There is one credential per server — no per-user accounts.
Returns
Description
1 HTTP Basic auth on localhost
SELECT httpserve_start('localhost', 9999, 'user:pass');
-- 'HTTP server started on localhost:9999'

-- From the shell:
--   curl -X POST -d "SELECT version()" http://user:pass@localhost:9999/
2 Single shared key (X-API-Key header)
SELECT httpserve_start('localhost', 9999, 'supersecretkey');

-- From the shell:
--   curl -X POST --header 'X-API-Key: supersecretkey' \
--        -d 'SELECT 42' http://localhost:9999/?default_format=JSONCompact
3 No auth — only behind a private network
SELECT httpserve_start('127.0.0.1', 9999, '');
4 Bind on all interfaces — read-only DuckDB, behind a TLS-terminating proxy
-- Launched as: duckdb -readonly mydata.duckdb
SELECT httpserve_start('0.0.0.0', 9999, 'shared-api-key');

httpserve_stop

Scalar function Server
Signature
httpserve_stop() VARCHAR
Returns
Description
1 Graceful stop
SELECT httpserve_stop();
2 Rotate credential without restarting DuckDB
SELECT httpserve_stop();
SELECT httpserve_start('localhost', 9999, 'rotated-key');