-
-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support net.http_delete with request body
Addresses #77 (comment). Now it's possible to do: ```sql select net.http_delete( url :='http://localhost:8080/delete_w_body' , body := '{"key": "val"}' ); ``` Backwards compatibility is tested. No body will be sent if the body parameter is NULL (the default).
- Loading branch information
1 parent
3cbe173
commit d312525
Showing
5 changed files
with
92 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
drop function net.http_delete (text, jsonb, jsonb, integer); | ||
|
||
create function net.http_delete( | ||
-- url for the request | ||
url text, | ||
-- 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 '{}'::jsonb, | ||
-- the maximum number of milliseconds the request may take before being cancelled | ||
timeout_milliseconds int default 5000, | ||
-- optional body of the request | ||
body jsonb default NULL | ||
) | ||
-- request_id reference | ||
returns bigint | ||
volatile | ||
parallel safe | ||
language plpgsql | ||
as $$ | ||
declare | ||
request_id bigint; | ||
params_array text[]; | ||
begin | ||
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 ( | ||
'DELETE', | ||
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 | ||
$$; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters