A naive HTTP JSON API for Postgres
Minimally-configurable, REST-like interaction with a postgres database.
go get github.com/daetal-us/grotto
- Requires Go.
- Requires an accessible instance of Postgres.
- Only table names containing alphanumeric, dashes and underscore characters will be accessible.
- Primary key columns for all tables assumed to be
id
.
grotto -addr :8080 -dsn postgres://user:password@host/db
The interface consists of standard HTTP request methods paired with the following path conventions:
path | description | GET (read) |
POST (create) |
PUT (update) |
DELETE |
---|---|---|---|---|---|
/ |
all available tables | √ | |||
/:table |
all rows in table | √ | |||
/:table/:id |
specific row in table | √ | √ | √ | √ |
All rows in hypothetical users
table:
GET /users HTTP/1.1
...
HTTP/1.1 200 OK
Content-Type: application/json; charset=UTF-8
...
{
"data": [
{
...
},
...
]
}
Single row in hypothetical users
table:
GET /users/1234 HTTP/1.1
...
HTTP/1.1 200 OK
Content-Type: application/json; charset=UTF-8
...
{
"data": {
"id": 1234,
...
}
}
Table not found:
GET /nonexistant-table HTTP/1.1
...
HTTP/1.1 404 Not Found
Content-Type: application/json; charset=UTF-8
...
{
"error": "Table not found."
}