API Reference (beta)

The parsers.dev API is organized around REST with JSON request and responses and uses standard HTTP response codes.
The current API status is BETA. Minor changes are possible before leaving this status. After fixing the state, JSON-schemas will be published, with a description of the formats of requests and responses

Authentication

The parsers.dev API uses API key to authenticate requests. You can view and manage your API key in the parsers.dev Account Settings.
The parsers.dev APIs is a REST-based service. Subsequently, all requests to the APIs require this HTTP header:
x-api-key: Your parsers.dev API key

Content type

The parsers.dev APIs is also a JSON-based service. You have to add Content-Type HTTP header to all your requests:
Content-Type: application/json

URL and API versioning

Only one API version is operating at this time. Use this base URL for your requests:
https://api.parsers.dev/api/v1

Responses

All responses are JSON-based and follow one of these formats:
// successful response
{
"status": "OK",
"data": {...}
}
}
// error response
{
"status": "ERROR",
"data": {
"code": <http-code>,
"message": "<error-message>",
"details": <mixed-object(optional)>,
}
}
Http codes and error message you can find at Errors section
post
https://api.parsers.dev
/api/v1/parse/:dialect
Parse SQL (SQL → AST)
Example:
JSON
JavaScript
Bash
{
"sql": "CREATE TABLE t(); SELECT 1; SELECT 1 FROM ; SELECT 2"
}
const axios = require ('axios');
const api_key = '<your-api-key>';
const data = {
sql: 'CREATE TABLE t(); SELECT 1; SELECT 1 FROM ; SELECT 2',
};
axios({
method: 'POST',
headers: {
'Content-Type': 'application/json',
'x-api-key': api_key,
},
data,
url: `https://api.parsers.dev/api/v1/parse/postgresql/`,
}).then((response) => {
console.log(response.data);
})
.catch(function (error) {
console.error('api.parsers.dev error:');
console.error(JSON.stringify(error.response.data, null, 2));
});
PARSERSDEV_API_KEY="<your-api-key>"; \
echo "{\"sql\": \"CREATE TABLE t(); SELECT 1; SELECT 2\"}" | \
curl \
--header "x-api-key: $PARSERSDEV_API_KEY" \
--header "Content-Type: application/json" \
--request POST --data @- https://api.parsers.dev/api/v1/parse/postgresql/
post
https://api.parsers.dev
/api/v1/compile/:dialect
Compile SQL (SQL → Special Object)
Example:
JSON
JavaScript
Bash
{
"ddl": "CREATE TABLE t (a int); CREATE",
"dmls": [
"table t; table t1",
"table",
"select * FROM t WHERE a = $1"
]
}
const axios = require ('axios');
const api_key = '<your-api-key>';
const data = {
ddl: 'CREATE TABLE t (a int); CREATE',
dmls: [
'table t; table t1',
'table',
'select * FROM t WHERE a = $1'
]
};
axios({
method: 'POST',
headers: {
'Content-Type': 'application/json',
'x-api-key': api_key,
},
data,
url: `https://api.parsers.dev/api/v1/compile/postgresql/`,
}).then((response) => {
console.log(response.data);
})
.catch(function (error) {
console.error('api.parsers.dev error:');
console.error(JSON.stringify(error.response.data, null, 2));
});
PARSERSDEV_API_KEY="<your-api-key>"; \
echo "{\"ddl\": \"CREATE TABLE t (a int); CREATE\", dml: [\"table t; table t1\", \"table\", \"select * FROM t WHERE a = $1\"]}" | \
curl \
--header "x-api-key: $PARSERSDEV_API_KEY" \
--header "Content-Type: application/json" \
--request POST --data @- https://api.parsers.dev/api/v1/compile/postgresql/
post
https://api.parsers.dev
/api/v1/tools/snowflake/getddl-reorder
Snowflake GET_DDL function result reorder
Example:
JSON
JavaScript
Bash
{
"sql": "create view v1 as select * from t; create table t (a int);"
}
const axios = require ('axios');
const api_key = '<your-api-key>';
const data = {
sql: 'create view v1 as select * from t; create table t (a int);'
};
axios({
method: 'POST',
headers: {
'Content-Type': 'application/json',
'x-api-key': api_key,
},
data,
url: `https://api.parsers.dev/api/v1/tools/snowflake/getddl-reorder`,
}).then((response) => {
console.log(response.data);
})
.catch(function (error) {
console.error('api.parsers.dev error:');
console.error(JSON.stringify(error.response.data, null, 2));
});
PARSERSDEV_API_KEY="<your-api-key>"; \
echo "{\"sql\": \"Create view v1 as select * from t; create table t (a int);\"}" | \
curl \
--header "x-api-key: $PARSERSDEV_API_KEY" \
--header "Content-Type: application/json" \
--request POST --data @- https://api.parsers.dev/api/v1/tools/snowflake/getddl-reorder
Last modified 2yr ago