apps/docs/content/guides/database/extensions/http.mdx
The http extension allows you to call RESTful endpoints within Postgres.
Let's cover some basic concepts:
GET − Read only access to a resource.POST − Creates a new resource.DELETE − Removes a resource.PUT − Updates an existing resource or creates a new resource.You can use the http extension to make these network requests from Postgres.
<Tabs scrollable size="small" type="underlined" defaultActiveId="dashboard" queryGroup="database-method"
<TabPanel id="dashboard" label="Dashboard">
http and enable the extension.-- Example: enable the "http" extension
create extension http with schema extensions;
-- Example: disable the "http" extension
drop extension if exists http;
Even though the SQL code is create extension, this is the equivalent of "enabling the extension".
To disable an extension, call drop extension.
It's good practice to create the extension within a separate schema (like extensions) to keep the public schema clean.
While the main usage is http('http_request'), there are 5 wrapper functions for specific functionality:
http_get()http_post()http_put()http_delete()http_head()A successful call to a web URL from the http extension returns a record with the following fields:
status: integercontent_type: character varyingheaders: http_header[]content: character varying. Typically you would want to cast this to jsonb using the format content::jsonbGET exampleselect
"status", "content"::jsonb
from
extensions.http_get('https://jsonplaceholder.typicode.com/todos/1');
POST exampleselect
"status", "content"::jsonb
from
extensions.http_post(
'https://jsonplaceholder.typicode.com/posts',
'{ "title": "foo", "body": "bar", "userId": 1 }',
'application/json'
);
http GitHub Repository