5

Would you be able to recommend a simple open-source library/tool to run in Linux, which would serve a REST-like API basically serving the content of SQL databases (in Postgres) over HTTP with friendly URLs? Python preferred, but not mandatory.

e.g. if you had a database with two tables:

employees (id, name, city, dep_id)
departments (id, name)

I would like to easily send HTTP requests like:

GET http://$HOST/employees?city=Paris
GET http://$HOST/employees?dep_id=4&city=Berlin,Paris
GET http://$HOST/departments?name=Legal,Finance

etc. I am flexible with whatever syntax needs to be used for URLs. But the goal is to avoid manual work of mapping these tables through ORM, then mapping that to URLs, etc. Ideally no programming needed at all (but allowed if I wanted to add a custom output format, etc.) Also I understand this tool could only offer SELECT with only limited WHERE clauses.

  • 1
    BTW the adminer.php and myphpadmin programs offer a full web based GUI. However, not access like above. – cybernard Dec 23 '16 at 4:26
4

You may try nginx HTTP server in conjunction with ngx_postgres module. ngx_postgres allows nginx to communicate with PostgreSQL database. Your basic requirements are satisfied as far as I see:

  • No programming needed. Only ngx_postgres configuration shall be specified to map URLs to DB queries.
  • At least SELECT with WHERE clause support (see examples on ngx_postgres web page).
  • PostgreSQL as a RDBMS.
  • HTTP protocol.
  • nginx is lightweight software.

You didn't specify response format you want to return to the clients, but ngx_postgres supports JSON.

2

RestifyDB (http://restifydb.com) is one solution. Its opensource and can be used free (unless you need patching etc for which there is a commercial version available. Though i have not used slash DB (https://www.slashdb.com/) is another solution which works on similar lines.

2

Sandman2 does exactly what you want, in python and advertises itself as Automatically generate a RESTful API service for your legacy database. No code required!

It uses SQLAlchemy for database interactions (and support any of its many supported DB) and offers not only a REST API but also a decent web Admin Interface.

Once, configured you should be able to issue queries such as http://$HOST/employees?city=Paris and similar though it may not support http://$HOST/employees?dep_id=4&city=Berlin,Paris where you ask for multiple values at once.... To be tested!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.