Skip to content

HTTP Server

Expose a running DuckDB process over HTTP so clients can POST a SQL query and read JSON results.

20,601
extension loads Β· last 90 days
On this page

Technical Overview

Why Run DuckDB Behind HTTP?

What this extension is for

  • β€’ Internal SQL APIs: Stand up a JSON query endpoint over a curated DuckDB database file so other services can pull aggregates without a client library. Pair with duckdb -readonly for safe shared access.
  • β€’ Ad-hoc browser exploration: The built-in quackplay UI lets a teammate paste a query into a browser tab and see results β€” useful when shipping a DuckDB file is easier than shipping a BI tool.
  • β€’ Cross-DuckDB query federation: Each DuckDB process is reachable over HTTP from any other DuckDB. Combined with the chsql extension's duck_flock macro, you can fan a single SQL statement out across multiple DuckDBs and merge the results.
  • β€’ Glue for DuckDB-Wasm: A browser-side DuckDB can POST to a server-side DuckDB through this extension to pull canonical data without bundling it into the page.

How it works

  • β€’ Endpoints: / accepts GET and POST for query execution. /ping is a GET health check. There is no /metrics, no /health, no OpenAPI document β€” the API surface is intentionally small.
  • β€’ Query input: POST the SQL as the request body, or send it as ?query= / ?q=. POST is recommended once the SQL exceeds typical URL length limits.
  • β€’ Response formats: Pass ?default_format=JSONEachRow for newline-delimited JSON (JSONEachRow) or JSONCompact for a single document with meta / data / rows / statistics keys (JSONCompact). The format vocabulary intentionally mirrors the ClickHouse HTTP interface so existing tooling works.
  • β€’ Authentication: The third argument to httpserve_start is one of: empty string (no auth), 'user:pass' (HTTP Basic), or any other value (treated as a single shared key sent in the X-API-Key header). There is one credential per server.

Production caveats

  • β€’ Run DuckDB read-only: The endpoint executes whatever SQL it receives against the connection's full surface. Without -readonly (see the DuckDB CLI docs), an authenticated client can ATTACH, INSERT, COPY TO, install extensions, or call file-system functions. The upstream README's first security note is exactly this.
  • β€’ No built-in TLS: The server speaks plain HTTP. Credentials and query results travel in the clear unless you front it with a TLS terminator like nginx, Caddy, or HAProxy. HTTP Basic without TLS is effectively no auth at all.
  • β€’ One credential, no per-user scope: Auth is binary: a request either presents the configured credential or it doesn't. There is no notion of users, roles, query allowlists, or rate limiting. For multi-tenant access, terminate auth at a gateway and run the server unauthenticated behind it on a private network.
  • β€’ Lock down the DuckDB itself: Even with -readonly, follow DuckDB's hardening guidance β€” disable community extension installation, restrict filesystem access, and consider running the process inside a sandbox or container.
  • β€’ Single process, no rate limiting: Concurrency and throughput are bounded by what one DuckDB process can do. There is no built-in request queue, no per-client throttling, and no slow-query cutoff. Put a reverse proxy in front for any of those.

Common Use Cases

Deep Dive

Technical Details

Install

INSTALL httpserver FROM community;
LOAD httpserver;

Quick Start

Start an HTTP API on localhost:9999 with Basic auth

SELECT httpserve_start('localhost', 9999, 'user:pass');

-- Any HTTP client can now POST queries:
-- curl -X POST -d "SELECT version()" http://user:pass@localhost:9999/

Stop when done

SELECT httpserve_stop();

Reference

Extension Contents

Quick reference to all available functions and settings organized by category.

Name Description
Server
httpserve_start() Start the embedded HTTP query server.
httpserve_stop() Stop the running HTTP server thread cleanly.

API Reference

Function Documentation

Practical Examples

Cookbook

Real-world recipes and patterns for common use cases.

Platform Support

Compatibility

Extension availability may vary by platform and DuckDB version. Check below to ensure this extension supports your environment before installation.

Quick Facts

Release status Stable
Software License MIT
Pricing Free
Written In C++
Source Available Yes
View on GitHub
Usage
20,601
loads Β· last 90 days

Platforms

Platform availability hasn't been recorded for this extension yet.

DuckDB & Haybarn

Release calendar
Not recorded for this extension.