http://127.0.0.1:8980/api/<db>/<table>/
GET / # Show status
GET /api # Show databases
GET /api/<db> # Show database tables
GET /api/<db>/<table> # Show database table fields
GET /api/<db>/<table>?query=true # List rows of table
POST /api/<db>/<table> # Create a new row
PUT /api/<db>/<table> # Replace existing row with new row
GET /api/<db>/<table>/:id # Retrieve a row by primary key
PATCH /api/<db>/<table>/:id # Update row element by primary key
DELETE /api/<db>/<table>/:id # Delete a row by primary key
GET /api/<db>/<table>/count # Count number of rows in a table
POST /api # Content-Type: text/sql
go get -u github.com/gin-gonic/gin
go get -u github.com/go-sql-driver/mysql
go run server.go
go build -o db-api server.go
go run server.go -port=8080
PORT=8080 go run server.go
python3 src/db_api_server/server.py
pip install db-api-server
$ db-api-server
* Serving Flask app "db_api_server.server" (lazy loading)
* Environment: production
WARNING: This is a development server. Do not use it in a production deployment.
Use a production WSGI server instead.
* Debug mode: off
* Running on http://127.0.0.1:8980/ (Press CTRL+C to quit)
python3 -m db_api_server
Any http client works
curl 127.0.0.1:8980/
curl --user dbuser:dbpass http://127.0.0.1:8980/api
curl --user dbuser:dbpass http://127.0.0.1:8980/api/mysql
curl --user dbuser:dbpass http://127.0.0.1:8980/api/mysql/user
curl --user dbuser:dbpass "http://127.0.0.1:8980/api/mysql/user?fields=user,host&limit=2,3"
curl --user dbuser:dbpass -H "X-Host: 127.0.1.1" -H "X-Port: 3307" "http://127.0.0.1:8980/api/example/table?fields=field1,field2,field3"
curl --user dbuser:dbpass http://127.0.0.1:8980/api/example/table1/3
get record 3 from example database table1 by name=47245ec8-a7d3-11eb-880f-acde48001122 with fields id,name (HTTP GET)
curl --user dbuser:dbpass http://127.0.0.1:8980/api/example/table1/47245ec8-a7d3-11eb-880f-acde48001122?column=name&fields=id,name"
curl --user dbuser:dbpass \
-X POST \
-H "Content-Type: application/json" \
--data '{"name":"hello","description":"inserted via curl"}' \
"http://127.0.0.1:8980/api/example/table1"
curl -X POST \
-H "Authorization: Basic <base64>" \
-H "Content-Type: application/json" \
--data '{"name":"hello","description":"inserted via post"}' \
"http://127.0.0.1:8980/api/example/table1"
<form action="http://127.0.0.1:8980/api/example/table1" method="POST">
<input type="text" name="credentials" value="base64">
<input type="text" name="name" value="name">
<input type="text" name="description" value="form data">
<input type="submit">
</form>
curl --user dbuser:dbpass \
-X PATCH \
-H "Content-Type: application/json" \
-H "Accept: application/json" \
-d '{"description": "A single colmn update"}' \
http://127.0.0.1:8980/api/example/table1/9
curl --user dbuser:dbpass \
-X PATCH \
-H "Content-Type: application/json" \
-H "Accept: application/json" \
-d '{"description": "A single colmn update2"}' \
"http://127.0.0.1:8980/api/example/table1/47245ec8-a7d3-11eb-880f-acde48001122?column=name"
curl --user dbuser:dbpass \
-X DELETE \
http://127.0.0.1:8980/api/example/table1/3
curl --user dbuser:dbpass \
-X DELETE \
"http://127.0.0.1:8980/api/example/table1/47245ec8-a7d3-11eb-880f-acde48001122?column=name"
curl --user dbuser:dbpass \
--request PUT \
--header 'Content-Type: application/json' \
--data '{"id":7, "name":"hello", "description":"replaced via curl"}' \
http://127.0.0.1:8980/api/example/table1
curl --user dbuser:dbpass \
-X POST \
-H "Content-Type: text/sql" \
--data "select * from db.table where id = '1234'" \
"http://127.0.0.1:8980/api"
curl --user dbuser:dbpass \
-H "X-Host: new-db-host" \
-H "X-Port: 3307" \
-H "X-Db: mydatabase" \
-H "X-Get-Warnings: true" \
-H "X-Auth-Plugin: mysql_native_password" \
-H "X-Pure: true" \
-H "X-Unicode: true" \
-H "X-Charset: utf8" \
-H "X-Connection-Timeout: 10" \
http://127.0.0.1:8980/api
import requests
req = requests.get('http://127.0.0.1:8980/api', auth=requests.auth.HTTPBasicAuth('username', 'password'))
print(req.json())
fetch('http://127.0.0.1:8980/api', {
method: 'GET',
headers: { Authorization: 'Basic ' + base64 }
})
.then(response => response.json())
.then(json => document.write(json))
.catch(err => document.write('Request Failed', err));
https://pypi.org/project/db-api-server
db-api-server
docker pull dcsops/db-api
https://hub.docker.com/r/dcsops/db-api
Flask
https://flask.palletsprojects.com/en/2.0.x/tutorial/deploy/
Gunicorn
https://gunicorn.org/#deployment
https://en.wikipedia.org/wiki/Representational_state_transfer