MySQL(or MariaDB) UDF(User-Defined Functions) Http Client Plugin.
MySQL or MariaDB UDF(User-Defined Functions) HTTP Client Plugin
Clone Source
git clone https://github.com/2rebi/mysql_udf_http_golang.git udf
cd udf
Auto Build
bash ./install.sh {username} {password}
{username} replace your MySQL or MariaDB Username.
{password} replace your MySQL or MariaDB Password(Optional).
Build output is
bash ./build.sh
http.so
, move file to plugin_dir
path.plugin_dir
path.
SHOW VARIABLES LIKE 'plugin_dir';
Ex)
$ mysql -u root -p
Enter password:
And
MariaDB [(none)]> SHOW VARIABLES LIKE 'plugin_dir';
+---------------+-----------------------------------------------+
| Variable_name | Value |
+---------------+-----------------------------------------------+
| plugin_dir | /usr/local/Cellar/mariadb/10.3.12/lib/plugin/ |
+---------------+-----------------------------------------------+
1 row in set (0.001 sec)
and http.so
move to Value
path.
mv ./http.so /usr/local/Cellar/mariadb/10.3.12/lib/plugin/
CREATE FUNCTION http_help RETURNS STRING SONAME 'http.so';
CREATE FUNCTION http_get RETURNS STRING SONAME 'http.so';
CREATE FUNCTION http_post RETURNS STRING SONAME 'http.so';
SELECT http_help();
Prototype
SELECT http_get(url, options...);
Simple Request
SELECT http_get('http://example.com');
Return
{
"Body" : String(HTML(Default), Base64, Hexdecimal)
}
Output Option
SELECT http_get('http://example.com', '-O FULL');
Return
{
"Proto" : String(Http Version, HTTP/1.0, HTTP/1.1, HTTP/2.0),
"Status" : String(Status Code, 200 OK, 404 NOT FOUND...),
"Header" : JSON(`{Key : Array, ...}`),
"Body" : String(HTML(Default), Base64, Hexdecimal)
}
-O {outputType}
Define kind of result.PROTO
, STATUS
or STATUS_CODE
, HEADER
, BODY
(default), FULL
-O PROTO|STATUS|HEADER|BODY
same this -O FULL
.
SELECT http_get('http://example.com', '-O FULL', '-H CustomKey:CustomValue', '-H Authorization:Bearer a1b2c3d4-123e-5678-9fgh-ijk098765432')
Like this
GET / HTTP/1.1
Host: example.com
CustomKey: CustomValue
Authorization: Bearer a1b2c3d4-123e-5678-9fgh-ijk098765432
User-Agent: Go-http-client/1.1
Accept-Encoding: gzip
Option param input -H {key}:{value}
.
SELECT http_post(url, contentType, body, options...)
SELECT http_post('http://example.com', '', '');
Like this
SELECT http_post('http://example.com', 'application/json', '{"Hello":"World"}');
{“Hello”:”World”}
### - Raw Method
- **Prototype**
```sql
SELECT http_raw(method, url, body, options...)
SELECT http_raw('PUT', url, body, options...)
SELECT http_raw('PATCH', url, body, options...)
SELECT http_raw('DELETE', url, body, options...)