# get ```sql CREATE OR REPLACE FUNCTION get(url TEXT) RETURNS TEXT LANGUAGE SQL AS $BODY$ WITH s AS (SELECT curl_easy_reset(), curl_easy_setopt_url(url), curl_easy_perform(header_in:=false), curl_easy_getinfo_data_in() ) SELECT convert_from(curl_easy_getinfo_data_in, 'utf-8') FROM s; $BODY$; ``` # urlencoded post ```sql CREATE OR REPLACE FUNCTION post(url TEXT, request JSON) RETURNS TEXT LANGUAGE SQL AS $BODY$ WITH s AS (SELECT curl_easy_reset(), curl_easy_setopt_copypostfields(( WITH s AS ( SELECT (json_each_text(request)).* ) SELECT convert_to(array_to_string(array_agg(concat_ws('=', curl_easy_escape(key), curl_easy_escape(value) )), '&'), 'utf-8') FROM s )), curl_easy_setopt_url(url), curl_easy_perform(header_in:=false), curl_easy_getinfo_data_in() ) SELECT convert_from(curl_easy_getinfo_data_in, 'utf-8') FROM s; $BODY$; ``` # json post ```sql CREATE OR REPLACE FUNCTION post(url TEXT, request JSON) RETURNS TEXT LANGUAGE SQL AS $BODY$ WITH s AS (SELECT curl_easy_reset(), curl_easy_setopt_copypostfields(convert_to(request::TEXT, 'utf-8')), curl_easy_setopt_url(url), curl_header_append('Content-Type', 'application/json; charset=utf-8'), curl_easy_perform(header_in:=false), curl_easy_getinfo_data_in() ) SELECT convert_from(curl_easy_getinfo_data_in, 'utf-8') FROM s; $BODY$; ``` # send email ```sql CREATE OR REPLACE FUNCTION email(url TEXT, username TEXT, password TEXT, subject TEXT, sender TEXT, recipient TEXT, body TEXT, type TEXT) RETURNS TEXT LANGUAGE SQL AS $BODY$ WITH s AS (SELECT curl_easy_reset(), curl_easy_setopt_mail_from(sender), curl_easy_setopt_password(password), curl_easy_setopt_url(url), curl_easy_setopt_username(username), curl_header_append('From', sender), curl_header_append('Subject', subject), curl_header_append('To', recipient), curl_mime_data(body, type:=type), curl_recipient_append(recipient), curl_easy_perform(data_in:=false), curl_easy_getinfo_header_in() ) SELECT curl_easy_getinfo_header_in FROM s; $BODY$; ```