Giter Site home page Giter Site logo

mysql_udf_http_golang's Introduction

mysql_udf_http_golang

MySQL UDF MariaDB UDF

MySQL or MariaDB UDF(User-Defined Functions) HTTP Client Plugin

Call RESTful API on query.

Setup

  • Clone Source
git clone https://github.com/solarflare045/mysql_udf_http_golang 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).

  • Manual Build
bash ./build.sh

Build output is http.so, move file to plugin_dir path.
if you don't know plugin_dir path.
Command input this on MySQL, MariaDB connection.

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/

Finally, execute query

  • Http Help
CREATE FUNCTION http_help RETURNS STRING SONAME 'http.so';
  • Http Get Method
CREATE FUNCTION http_get RETURNS STRING SONAME 'http.so';
  • Http Post Method
CREATE FUNCTION http_post RETURNS STRING SONAME 'http.so';

Usage

- Help

SELECT http_help();

- GET Method

  • 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.

  • Custom Header
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}.

- POST Method

  • Prototype
SELECT http_post(url, contentType, body, options...)
  • Simple Request(No Body)
SELECT http_post('http://example.com', '', '');
  • Simple Request(Json Body)
SELECT http_post('http://example.com', 'application/json', '{"Hello":"World"}');

Like this

POST / HTTP/1.1
Host: example.com
Content-Type: application/json
Content-Length: 17
User-Agent: Go-http-client/1.1
Accept-Encoding: gzip


{"Hello":"World"}

- Raw Method

  • Prototype
SELECT http_raw(method, url, body, options...)
  • PUT
SELECT http_raw('PUT', url, body, options...)
  • PATCH
SELECT http_raw('PATCH', url, body, options...)
  • DELETE
SELECT http_raw('DELETE', url, body, options...)

License

THE BEER-WARE LICENSE (Revision 42)

mysql_udf_http_golang's People

Contributors

2rebi avatar solarflare045 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.