text: create or replace function net.http_post(
      -- url for the request
      url text,
      -- body of the POST request
      body jsonb default '{}'::jsonb,
      -- key/value pairs to be url encoded and appended to the `url`
      params jsonb default '{}'::jsonb,
      -- key/values to be included in request headers
      headers jsonb default '{"Content-Type": "application/json"}'::jsonb,
      -- the maximum number of milliseconds the request may take before being cancelled
      timeout_milliseconds int DEFAULT 1000
  )
      -- request_id reference
      returns bigint
      volatile
      parallel safe
      language plpgsql
  as $$
  declare
      request_id bigint;
      params_array text[];
      content_type text;
  begin
  
      -- Exctract the content_type from headers
      select
          header_value into content_type
      from
          jsonb_each_text(coalesce(headers, '{}'::jsonb)) r(header_name, header_value)
      where
          lower(header_name) = 'content-type'
      limit
          1;
  
      -- If the user provided new headers and omitted the content type
      -- add it back in automatically
      if content_type is null then
          select headers || '{"Content-Type": "application/json"}'::jsonb into headers;
      end if;
  
      -- Confirm that the content-type is set as "application/json"
      if content_type <> 'application/json' then
          raise exception 'Content-Type header must be "application/json"';
      end if;
  
      -- Confirm body is set since http method switches on if body exists
      if body is null then
          raise exception 'body must not be null';
      end if;
  
      select
          coalesce(array_agg(net._urlencode_string(key) || '=' || net._urlencode_string(value)), '{}')
      into
          params_array
      from
          jsonb_each_text(params);
  
      -- Add to the request queue
      insert into net.http_request_queue(method, url, headers, body, timeout_milliseconds)
      values (
          'POST',
          net._encode_url_with_params_array(url, params_array),
          headers,
          convert_to(body::text, 'UTF8'),
          timeout_milliseconds
      )
      returning id
      into request_id;
  
      return request_id;
  end
  $$;
  