MySQL数据库的HTTP接口:MySQL HTTP API

pnxx 8年前

此HTTP服务器提供了一个HTTP接口直接可以访问到MySQL数据库。允许客户端通过Http来与MySQL数据库交互。

Running/Installing

It's easy to run the HTTP server for this. Just clone the repo, install the dependencies and run the web server through bundler.

git clone https://github.com/adamcooke/mysql-api  cd mysql-api  bundle  bundle exec rackup

Bare in mind that the server that you install this on will need to be able to access the databases which you connecting to.

Using the API

Once the server is running you can send requests to it containing server credentials and the queries you want to execute. You should send the queries to the/queryendpoint.

The body of your request should be JSON-formatted and the content type for the request must beapplication/json.

An example request looks like this:

{    "host":"localhost",    "username":"root",    "password":"supersecretpassword",    "database":"mydatabase",    "queries":[      {        "name":"explain",        "query":"EXPLAIN users;"      },      {        "name":"total_count",        "query":"SELECT COUNT(id) AS count FROM users;"      },      {        "name":"records",        "query":"SELECT * FROM users LIMIT 10;"      },      {        "name":"prepared_query",        "query":"SELECT * FROM users WHERE username = ? AND first_name = ?;"        "values":["adamcooke", "Adam"]      }    ]  }

项目主页:http://www.open-open.com/lib/view/home/1443361570658