http
Overview
| Package | Version | Category | License | Language |
|---|---|---|---|---|
pg_http | 1.7.1 | 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 | MIXED | 1.7.1 | 1817161514 | pg_http | - |
| RPM | PIGSTY | 1.7.1 | 1817161514 | pgsql_http_$v | - |
| DEB | PGDG | 1.7.1 | 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 and PIGSTY repositories are added and enabled:
pig repo add pgsql -u # Add 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 pgsql_http_18 # PG 18
dnf install -y pgsql_http_17 # PG 17
dnf install -y pgsql_http_16 # PG 16
dnf install -y pgsql_http_15 # PG 15
dnf install -y pgsql_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
Sources: README, v1.7.1 release
http lets SQL code make HTTP requests through libcurl. Use it for controlled integration points such as triggers that notify an external service, SQL jobs that fetch a small remote payload, or database-side webhook calls.
CREATE EXTENSION http;
Request And Response Types
Every request uses http_request and returns http_response:
http_request(method http_method, uri varchar, headers http_header[], content_type varchar, content varchar)
http_response(status integer, content_type varchar, headers http_header[], content varchar)
Convenience wrappers call the same underlying http(http_request) function:
http_get(uri varchar)http_get(uri varchar, data jsonb)http_post(uri varchar, content varchar, content_type varchar)http_post(uri varchar, data jsonb)http_put(uri varchar, content varchar, content_type varchar)http_patch(uri varchar, content varchar, content_type varchar)http_delete(uri varchar)http_head(uri varchar)
Examples
SELECT status, content_type, content
FROM http_get('https://httpbun.com/ip');
SELECT content::json->'headers'->>'Authorization'
FROM http((
'GET',
'https://httpbun.com/headers',
http_headers('Authorization', 'Bearer token'),
NULL,
NULL
)::http_request);
SELECT status, content::json->'form' AS form
FROM http_post(
'https://httpbun.com/post',
jsonb_build_object('myvar', 'myval', 'foo', 'bar')
);
SELECT status, content_type, content::json->>'data' AS data
FROM http_put('https://httpbun.com/put', 'some text', 'text/plain');
Inspect response headers by unnesting the headers array:
SELECT (unnest(headers)).*
FROM http_get('https://httpbun.com/');
Binary Content
The README warns that varchar::bytea is not safe for binary response bodies because it stops at zero-valued bytes. Use text_to_bytea(content) for response content and bytea_to_text(bytea) when sending binary request bodies.
WITH http AS (
SELECT * FROM http_get('https://httpbingo.org/image/png')
)
SELECT content_type, length(text_to_bytea(content)) AS bytes
FROM http;
Timeout And Version Notes
pg_http 1.7.1 is a compatibility and documentation release: it adds timeout examples, adds PostgreSQL 17 wait-event hooks, and includes PostgreSQL 19 support fixes. The user-facing SQL API remains the README surface above.
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.