CREATE EXTENSION http; set http.timeout_msec = 10000; SELECT http_set_curlopt('CURLOPT_TIMEOUT', '10'); http_set_curlopt ------------------ t (1 row) -- Status code SELECT status FROM http_get('https://httpbin.org/status/202'); status -------- 202 (1 row) -- Headers SELECT * FROM ( SELECT (unnest(headers)).* FROM http_get('https://httpbin.org/response-headers?Abcde=abcde') ) a WHERE field = 'Abcde'; field | value -------+------- Abcde | abcde (1 row) -- GET SELECT status, content::json->'args' AS args, content::json->'url' AS url, content::json->'method' AS method FROM http_get('https://httpbin.org/anything?foo=bar'); status | args | url | method --------+------------------+----------------------------------------+-------- 200 | { +| "https://httpbin.org/anything?foo=bar" | "GET" | "foo": "bar"+| | | } | | (1 row) -- GET with data SELECT status, content::json->'args' as args, content::json->>'data' as data, content::json->'url' as url, content::json->'method' as method from http(('GET', 'https://httpbin.org/anything', NULL, 'application/json', '{"search": "toto"}')); status | args | data | url | method --------+------+--------------------+--------------------------------+-------- 200 | {} | {"search": "toto"} | "https://httpbin.org/anything" | "GET" (1 row) -- DELETE SELECT status, content::json->'args' AS args, content::json->'url' AS url, content::json->'method' AS method FROM http_delete('https://httpbin.org/anything?foo=bar'); status | args | url | method --------+------------------+----------------------------------------+---------- 200 | { +| "https://httpbin.org/anything?foo=bar" | "DELETE" | "foo": "bar"+| | | } | | (1 row) -- PUT SELECT status, content::json->'data' AS data, content::json->'args' AS args, content::json->'url' AS url, content::json->'method' AS method FROM http_put('https://httpbin.org/anything?foo=bar','payload','text/plain'); status | data | args | url | method --------+-----------+------------------+----------------------------------------+-------- 200 | "payload" | { +| "https://httpbin.org/anything?foo=bar" | "PUT" | | "foo": "bar"+| | | | } | | (1 row) -- PATCH SELECT status, content::json->'data' AS data, content::json->'args' AS args, content::json->'url' AS url, content::json->'method' AS method FROM http_patch('https://httpbin.org/anything?foo=bar','{"this":"that"}','application/json'); status | data | args | url | method --------+-----------------------+------------------+----------------------------------------+--------- 200 | "{\"this\":\"that\"}" | { +| "https://httpbin.org/anything?foo=bar" | "PATCH" | | "foo": "bar"+| | | | } | | (1 row) -- POST SELECT status, content::json->'data' AS data, content::json->'args' AS args, content::json->'url' AS url, content::json->'method' AS method FROM http_post('https://httpbin.org/anything?foo=bar','payload','text/plain'); status | data | args | url | method --------+-----------+------------------+----------------------------------------+-------- 200 | "payload" | { +| "https://httpbin.org/anything?foo=bar" | "POST" | | "foo": "bar"+| | | | } | | (1 row) -- HEAD SELECT * FROM ( SELECT (unnest(headers)).* FROM http_head('https://httpbin.org/response-headers?Abcde=abcde') ) a WHERE field = 'Abcde'; field | value -------+------- Abcde | abcde (1 row) -- Follow redirect SELECT status, content::json->'args' AS args, content::json->'url' AS url FROM http_get('https://httpbin.org/redirect-to?url=http%3A%2F%2Fhttpbin%2Eorg%2Fget%3Ffoo%3Dbar'); status | args | url --------+------------------+----------------------------------- 200 | { +| "https://httpbin.org/get?foo=bar" | "foo": "bar"+| | } | (1 row) -- Request image WITH http AS ( SELECT * FROM http_get('https://httpbin.org/image/png') ), headers AS ( SELECT (unnest(headers)).* FROM http ) SELECT http.content_type, length(textsend(http.content)) AS length_binary, headers.value AS length_headers FROM http, headers WHERE field = 'Content-Length'; content_type | length_binary | length_headers --------------+---------------+---------------- image/png | 8090 | 8090 (1 row) -- Alter options and and reset them and throw errors SELECT http_set_curlopt('CURLOPT_PROXY', '127.0.0.1'); http_set_curlopt ------------------ t (1 row) -- Error because proxy is not there SELECT status FROM http_get('https://httpbin.org/status/555'); ERROR: Failed to connect to 127.0.0.1 port 1080: Connection refused -- Still an error SELECT status FROM http_get('https://httpbin.org/status/555'); ERROR: Failed to connect to 127.0.0.1 port 1080: Connection refused SELECT http_reset_curlopt(); http_reset_curlopt -------------------- t (1 row) -- Now it should work SELECT status FROM http_get('https://httpbin.org/status/555'); status -------- 555 (1 row) -- Alter the default timeout and then run a query that is longer than -- the default (5s), but shorter than the new timeout SELECT http_set_curlopt('CURLOPT_TIMEOUT_MS', '10000'); http_set_curlopt ------------------ t (1 row) SELECT status FROM http_get('http://httpstat.us/200?sleep=7000'); status -------- 200 (1 row)