On this page

HTTP from SQL

Send HTTP requests from SQL and triggers with pg_net (net.http_get, net.http_post, net.http_delete).

Enable pg_net under Database → Extensions or with SQL. Requests are asynchronous: the functions return a request id right away, the platform sends the request in the background, and the response appears in net._http_response.

SQL
create extension if not exists pg_net with schema extensions;

-- Queue a request; returns its id immediately
select net.http_get('https://api.example.com/status') as request_id;

select net.http_post(
  url := 'https://hooks.example.com/orders',
  body := jsonb_build_object('order_id', 42),
  headers := '{"Content-Type": "application/json", "Authorization": "Bearer <token>"}'::jsonb,
  timeout_milliseconds := 10000
);

-- A moment later
select id, status_code, content, error_msg from net._http_response order by id desc limit 5;

#Webhook from a trigger

SQL
create or replace function public.notify_new_order() returns trigger
language plpgsql as $$
begin
  perform net.http_post(
    url := 'https://hooks.example.com/orders',
    body := to_jsonb(new)
  );
  return new;
end $$;

create trigger orders_webhook after insert on public.orders
  for each row execute function public.notify_new_order();

#Limits

LimitValue
MethodsGET, POST, DELETE
Schemeshttp and https
Timeout5 s by default, at most 30 s
Request and response body1 MB each (the response limit applies after decompression)
URL length8,192 characters
Rate20 requests per second per project (bursts of 40), 8 at a time
RedirectsNot followed: a 3xx response is stored as it is
Responses kept6 hours

#Blocked destinations

Requests may only go to public addresses on ports 80, 443 and 1024-65535. The check runs on the address actually connected to, so DNS tricks don't get around it. Blocked:

  • Private networks: 10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16, 100.64.0.0/10 and fc00::/7.
  • Loopback and link-local: 127.0.0.0/8, ::1, 169.254.0.0/16 (including cloud metadata addresses) and fe80::/10.
  • Reserved, documentation, multicast and transition ranges such as 0.0.0.0/8, 192.0.2.0/24, 198.18.0.0/15, 224.0.0.0/4, 240.0.0.0/4, 2001:db8::/32 and ff00::/8.
  • Host names localhost and anything ending in .localhost, .local or .internal.
  • StitchDB's own servers, except on ports 80 and 443.

Recent responses (the last 100) and the number of queued requests are listed in Studio under Integrations → HTTP requests.

Was this helpful?