http
HTTP client for PostgreSQL, allows web page retrieval inside the database.
Repository
pramsey/pgsql-http
https://github.com/pramsey/pgsql-http
Source
pgsql-http-1.7.0.tar.gz
pgsql-http-1.7.0.tar.gz
Overview
| Package | Version | Category | License | Language |
|---|---|---|---|---|
pg_http | 1.7.0 | UTIL | MIT | C |
| ID | Extension | Bin | Lib | Load | Create | Trust | Reloc | Schema |
|---|---|---|---|---|---|---|---|---|
| 4070 | http | No | Yes | No | Yes | No | No | - |
| Related | pg_net pg_curl pgjwt pg_smtp_client gzip bzip zstd pgjq pgmb |
|---|
Version
| Type | Repo | Version | PG Ver | Package | Deps |
|---|---|---|---|---|---|
| EXT | PGDG | 1.7.0 | 1817161514 | pg_http | - |
| RPM | PGDG | 1.7.0 | 1817161514 | pg_http_$v | - |
| DEB | PGDG | 1.7.0 | 1817161514 | postgresql-$v-http | - |
Build
You can build the RPM packages for pg_http using pig build:
pig build pkg pg_http # build RPM packages
Install
You can install pg_http directly. First, make sure the PGDG repository is added and enabled:
pig repo add pgdg -u # Add PGDG repo and update cache
Install the extension using pig or apt/yum/dnf:
pig install pg_http; # Install for current active PG version
pig ext install -y pg_http -v 18 # PG 18
pig ext install -y pg_http -v 17 # PG 17
pig ext install -y pg_http -v 16 # PG 16
pig ext install -y pg_http -v 15 # PG 15
pig ext install -y pg_http -v 14 # PG 14
dnf install -y pg_http_18 # PG 18
dnf install -y pg_http_17 # PG 17
dnf install -y pg_http_16 # PG 16
dnf install -y pg_http_15 # PG 15
dnf install -y pg_http_14 # PG 14
apt install -y postgresql-18-http # PG 18
apt install -y postgresql-17-http # PG 17
apt install -y postgresql-16-http # PG 16
apt install -y postgresql-15-http # PG 15
apt install -y postgresql-14-http # PG 14
Create Extension:
CREATE EXTENSION http;
Usage
https://github.com/pramsey/pgsql-http
Request / Response Schema:
Composite type "public.http_request"
Column | Type | Modifiers
--------------+-------------------+-----------
method | http_method |
uri | character varying |
headers | http_header[] |
content_type | character varying |
content | character varying |
Composite type "public.http_response"
Column | Type | Modifiers
--------------+-------------------+-----------
status | integer |
content_type | character varying |
headers | http_header[] |
content | character varying |
Examples
Sending HTTP GET requests with SQL
CREATE EXTENSION http;
-- get content
SELECT content FROM http_get('http://httpbun.com/');
-- get status and content_type
SELECT status, content_type FROM http_get('http://httpbun.com/');
-- status | content_type
-- --------+--------------------------
-- 200 | text/html; charset=utf-8
-- get headers
SELECT (unnest(headers)).* FROM http_get('http://httpbun.com/');
-- field | value
-- ---------------------------+--------------------------------------------------
-- Location | https://httpbun.com/
-- Date | Mon, 04 Nov 2024 09:00:36 GMT
-- Content-Length | 0
-- Connection | close
-- alt-svc | h3=":443"; ma=2592000
-- content-security-policy | frame-ancestors 'none'
-- content-type | text/html
-- date | Mon, 04 Nov 2024 09:00:37 GMT
-- strict-transport-security | max-age=31536000; includeSubDomains; preload
-- x-content-type-options | nosniff
-- x-powered-by | httpbun/af040d24038613575a85f74c2283ae79f8169927
-- (11 rows)
SELECT status, content::json->'form' AS form FROM http_post('http://httpbun.com/post', jsonb_build_object('myvar','myval','foo','bar'));
Issue http put requests:
SELECT status, content_type, content::json->>'data' AS data
FROM http_put('http://httpbun.com/put', 'some text', 'text/plain');
-- status | content_type | data
-- --------+------------------+-----------
-- 200 | application/json | some text
Issue http post request:
Feedback
Was this page helpful?
Thanks for the feedback! Please let us know how we can improve.
Sorry to hear that. Please let us know how we can improve.