http — HTTP Client
Make HTTP requests directly from SQL.
Installation
Section titled “Installation”CREATE EXTENSION http;Basic Usage
Section titled “Basic Usage”-- GET requestSELECT http_get('https://api.example.com/data');
-- POST request with JSON bodySELECT http_post( 'https://api.example.com/endpoint', '{"key": "value"}', 'application/json');Available Functions
Section titled “Available Functions”| Function | Description |
|---|---|
http_get(url) | HTTP GET request |
http_post(url, body, content_type) | HTTP POST request |
http_put(url, body, content_type) | HTTP PUT request |
http_delete(url) | HTTP DELETE request |
http_head(url) | HTTP HEAD request |
http_patch(url, body, content_type) | HTTP PATCH request |
Parse JSON Response
Section titled “Parse JSON Response”SELECT (http_get('https://api.ipify.org?format=json'))::json->>'ip' as my_ip;Response Structure
Section titled “Response Structure”The http functions return a composite type with these fields:
| Field | Type | Description |
|---|---|---|
status | INT | HTTP status code (200, 404, etc.) |
content_type | TEXT | Response Content-Type header |
headers | JSONB | All response headers |
content | TEXT | Response body |
Real-World Examples
Section titled “Real-World Examples”POST to Webhook
Section titled “POST to Webhook”-- Send alert to webhookSELECT http_post( 'https://hooks.slack.com/services/xxx/yyy/zzz', '{"text": "Database backup completed!"}', 'application/json');Check URL Status
Section titled “Check URL Status”-- Health check multiple endpointsSELECT url, (http_head(url)).status as statusFROM (VALUES ('https://api.example.com/health'), ('https://db9.ai'), ('https://google.com')) t(url);Security: DB9 has built-in SSRF protection. Requests to internal/private IP ranges are blocked.
Related Docs
Section titled “Related Docs”- HTTP from SQL Guide — tutorial: call APIs, send webhooks, and enrich data from SQL
- Extensions Overview — all 9 built-in extensions
- Scheduled Jobs with pg_cron — combine HTTP calls with scheduled jobs