Complete reference for QueryLab's backend API endpoints.
Production: https://your-worker.your-subdomain.workers.dev
Development: http://localhost:8787
Most endpoints require authentication via JWT cookies. The authentication flow:
POST /auth/login- Initiate login (sends verification code)POST /auth/login/verify- Verify code and get auth tokenGET /auth/me- Get current user infoPOST /auth/logout- Logout and clear session
Check API health status.
Response:
{
"success": true,
"data": {
"status": "ok",
"timestamp": "2024-01-01T00:00:00.000Z",
"service": "querylab-backend"
}
}Generate SQL from natural language.
Authentication: Required
Request Body:
{
"prompt": "Show me all students older than 20",
"runSql": false,
"schema": {
"tables": [
{
"name": "students",
"columns": [
{"name": "id", "type": "INTEGER"},
{"name": "name", "type": "TEXT"},
{"name": "age", "type": "INTEGER"}
]
}
]
}
}Response:
{
"success": true,
"data": {
"sql": "SELECT * FROM students WHERE age > 20",
"validated": true
}
}Rate Limit: 30 requests per minute
Fix SQL errors using AI.
Authentication: Required
Request Body:
{
"errorSql": "SELECT * FROM studnts",
"errorMessage": "no such table: studnts",
"schema": {
"tables": [...]
}
}Response:
{
"success": true,
"data": {
"fixedSql": "SELECT * FROM students",
"explanation": "Fixed table name typo"
}
}Rate Limit: 30 requests per minute
Get SQL query suggestions.
Authentication: Required
Request Body:
{
"prompt": "find students",
"schema": {
"tables": [...]
}
}Response:
{
"success": true,
"data": {
"suggestions": [
"SELECT * FROM students",
"SELECT name, age FROM students"
]
}
}Initiate login process.
Request Body:
{
"email": "user@ucsiuniversity.edu.my",
"name": "John Doe"
}Response:
{
"success": true,
"data": {
"message": "Verification code sent",
"status": "AUTH_PENDING"
}
}Cookies: Sets _auth.jti cookie (session ID)
Verify login code.
Request Body:
{
"code": "123456"
}Cookies: Requires _auth.jti cookie
Response:
{
"success": true,
"data": {
"message": "Email verified successfully",
"email": "user@ucsiuniversity.edu.my"
}
}Cookies: Sets _auth.t cookie (JWT token)
Get current user information.
Authentication: Required (JWT cookie)
Response:
{
"success": true,
"data": {
"email": "user@ucsiuniversity.edu.my",
"name": "John Doe",
"university": "UCSI University"
}
}Logout current user.
Authentication: Required
Response:
{
"success": true,
"data": {
"message": "Logged out successfully"
}
}All endpoints return errors in this format:
{
"success": false,
"data": null,
"error": {
"message": "Error description",
"code": "ERROR_CODE",
"details": {}
}
}AUTH_MISSING: Authentication requiredRATE_LIMIT_EXCEEDED: Too many requestsVALIDATION_ERROR: Invalid request dataNOT_FOUND: Resource not foundINTERNAL_ERROR: Server error
- AI endpoints: 30 requests per minute per user
- Other endpoints: No specific limit (subject to Cloudflare Workers limits)
The API supports CORS with:
Access-Control-Allow-Origin: Configured frontend URLAccess-Control-Allow-Credentials: trueAccess-Control-Allow-Methods: GET, POST, PUT, DELETE, OPTIONS
- Maximum request body: 1MB
- SQL queries: No specific limit (but large queries may timeout)