Skip to main content

What is SQL for APIs?

SQL for APIs is a design pattern that projects API operations onto relational semantics: list and get operations become SELECT, create operations become INSERT, modify operations become UPDATE or REPLACE, and remove operations become DELETE. The API's response objects become rows; their attributes become columns. The pattern gives any REST or RPC API the ergonomics of a database without requiring the API provider to change anything.

How it works

The mapping is mechanical, which is what makes it generalizable:

API conceptRelational concept
Provider (AWS, GitHub)Schema namespace
Service (EC2, repos)Sub-schema
Resource collectionTable
List / get operationSELECT method
Create operationINSERT method
Patch / put operationUPDATE / REPLACE method
Delete operationDELETE method
Other lifecycle actions (start, stop, reboot)EXEC method
Required path or query parametersRequired WHERE clause predicates
Request body fieldsdata__ prefixed insert/update columns

In StackQL, this mapping is generated from extended OpenAPI specifications held in the open StackQL provider registry. The required API parameters are discoverable at runtime: SHOW METHODS IN aws.ec2.instances returns each method's SQL verb and its required parameters, so a human or an AI agent can derive a correct query without reading provider documentation.

Example

A read is a SELECT whose WHERE clause carries the API's required parameters:

SELECT name, language, stargazers_count
FROM github.repos.repos
WHERE org = 'stackql';

A create is an INSERT whose columns carry the request body (prefixed data__) and routing parameters:

INSERT INTO google.storage.buckets(
project,
data__name,
data__location
)
SELECT
'my-project',
'my-new-bucket',
'US';

SHOW INSERT INTO google.storage.buckets generates this template mechanically, including all writable fields.

Why it exists

SQL is the most widely deployed query language in existence, with fifty years of tooling: drivers, ORMs, BI platforms, notebooks, and - increasingly important - LLM training data. Every mainstream AI model can already read and write competent SQL. Projecting APIs into SQL means all of that tooling and model capability applies to any API surface immediately. The alternative - one SDK per provider per language - multiplies integration work and gives agents nothing reusable. The argument is developed further in Why SQL is a Strong Interface for Cloud APIs.