Let's say I have a machine-readable description (such as in WADL, Swagger or RAML) of a REST API that provides interface to a database.
My users submit queries about underlying database in form of SQL or similar query language. However, I cannot access the database directly, only through the REST API.
What approach would you choose to build (preferably semi-automatically from description) a system that translates such SQL queries into a sequence of requests to given REST API?
How would you represent such problem? Are there any algorithms, theoretical frameworks or tools that can help?
The REST API supports:
- read-only operations, i.e. only
SELECT
SQL queries - XPartial projections (e.g.
/persons?fields=firstname,lastname
) - RSQL constraints (
/persons?query=firstname==John;department.code==42
, see another examples).
Some references between tables (foreign keys) are represented as attributes in the REST API (such as Person.department
in above constraints example), but some references are represented as subresource (e.g. /persons/{userName}/projects
). This means that some queries requires to devise "a plan" to be answered in terms of REST requests.
E.g.: Query for "names of active projects of Chuck Norris" would translate to:
/persons?query=firstname==Chuck;lastname==Norris
- Get
userName
from result /projects/{userName}?fields=name&query=state==ACTIVE