http

HTTP client for PostgreSQL, allows web page retrieval inside the database.

Overview

PGDG 1st Party Extension: pg_http : HTTP client for PostgreSQL, allows web page retrieval inside the database.

Information

Metadata

  • Latest Version: 1.6
  • Postgres Support: 17,16,15,14,13
  • Need Load: Shared library do not need explicit loading
  • Need DDL: Need CREATE EXTENSION DDL
  • Relocatable: Unknown
  • Trusted: Untrusted, Require Superuser to Create
  • Schemas: N/A
  • Requires: N/A

RPM / DEB

  • RPM Repo: PGDG
  • RPM Name: pgsql_http_$v*
  • RPM Ver : 1.6
  • RPM Deps: N/A
  • DEB Repo: PGDG
  • DEB Name: postgresql-$v-http
  • DEB Ver : 1.6
  • DEB Deps: N/A

Packages

OS Arch PG17 PG16 PG15 PG14 PG13
el8 x86_64 pgsql_http_17
PGDG 1.6.3
pgsql_http_16
PGDG 1.6.3
pgsql_http_15
PGDG 1.6.3
pgsql_http_14
PGDG 1.6.3
pgsql_http_13
PGDG 1.6.3
el8 aarch64 pgsql_http_17
PGDG 1.6.3
pgsql_http_16
PGDG 1.6.3
pgsql_http_15
PGDG 1.6.3
pgsql_http_14
PGDG 1.6.3
pgsql_http_13
PGDG 1.6.3
el9 x86_64 pgsql_http_17
PGDG 1.6.3
pgsql_http_16
PGDG 1.6.3
pgsql_http_15
PGDG 1.6.3
pgsql_http_14
PGDG 1.6.3
pgsql_http_13
PGDG 1.6.3
el9 aarch64 pgsql_http_17
PGDG 1.6.3
pgsql_http_16
PGDG 1.6.3
pgsql_http_15
PGDG 1.6.3
pgsql_http_14
PGDG 1.6.3
pgsql_http_13
PGDG 1.6.3
d12 x86_64 postgresql-17-http
PGDG 1.6.3
postgresql-16-http
PGDG 1.6.3
postgresql-15-http
PGDG 1.6.3
postgresql-14-http
PGDG 1.6.3
postgresql-13-http
PGDG 1.6.3
d12 aarch64 postgresql-17-http
PGDG 1.6.3
postgresql-16-http
PGDG 1.6.3
postgresql-15-http
PGDG 1.6.3
postgresql-14-http
PGDG 1.6.3
postgresql-13-http
PGDG 1.6.3
u22 x86_64 postgresql-17-http
PGDG 1.6.3
postgresql-16-http
PGDG 1.6.3
postgresql-15-http
PGDG 1.6.3
postgresql-14-http
PGDG 1.6.3
postgresql-13-http
PGDG 1.6.3
u22 aarch64 postgresql-17-http
PGDG 1.6.3
postgresql-16-http
PGDG 1.6.3
postgresql-15-http
PGDG 1.6.3
postgresql-14-http
PGDG 1.6.3
postgresql-13-http
PGDG 1.6.3
u24 x86_64 postgresql-17-http
PGDG 1.6.3
postgresql-16-http
PGDG 1.6.3
postgresql-15-http
PGDG 1.6.3
postgresql-14-http
PGDG 1.6.3
postgresql-13-http
PGDG 1.6.3
u24 aarch64 postgresql-17-http
PGDG 1.6.3
postgresql-16-http
PGDG 1.6.3
postgresql-15-http
PGDG 1.6.3
postgresql-14-http
PGDG 1.6.3
postgresql-13-http
PGDG 1.6.3

Installation

Install http via the pig CLI tool:


pig ext install pg_http; # Extension Namepig ext install http; # normalized package name

Install pg_http via Pigsty playbook:

./pgsql.yml -t pg_extension -e '{"pg_extensions": ["pg_http"]}' # -l <cls>

Install pg_http RPM from YUM repo directly:

dnf install pgsql_http_17*;
dnf install pgsql_http_16*;
dnf install pgsql_http_15*;
dnf install pgsql_http_14*;
dnf install pgsql_http_13*;

Install pg_http DEB from APT repo directly:

apt install postgresql-17-http;
apt install postgresql-16-http;
apt install postgresql-15-http;
apt install postgresql-14-http;
apt install postgresql-13-http;

Enable http extension on PostgreSQL cluster:

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:





Last modified 2025-02-17: add extension part (cfa504b)