Search Shortcut cmd + k | ctrl + k
httpserver

DuckDB HTTP API Server Extension

Installing and Loading

INSTALL httpserver FROM community;
LOAD httpserver;

Example

-- 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)" "http://localhost: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`

![image info](https://private-user-images.githubusercontent.com/1423657/376339324-e930a8d2-b3e4-454e-ba12-e5e91b30bfbe.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MzMzNDI2MTksIm5iZiI6MTczMzM0MjMxOSwicGF0aCI6Ii8xNDIzNjU3LzM3NjMzOTMyNC1lOTMwYThkMi1iM2U0LTQ1NGUtYmExMi1lNWU5MWIzMGJmYmUucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI0MTIwNCUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNDEyMDRUMTk1ODM5WiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9ZjI5OTEwZGNhM2NhZGI4NDJiYTE5ZmM1ZWIzZDE4OTBkZDY3ODBkMTkxM2E1ZWNiMjRmZDAzNzlkOWEyMjVmMiZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QifQ.iCK1p26RFbEjMWPyG5i8XmhPyzUn8J9cCsm1N1T8y5E)

About httpserver

This extension is experimental and potentially unstable. Do not use it in production.

Added Functions

function_name function_type description comment example
httpserve_start scalar      
httpserve_stop scalar