-
Notifications
You must be signed in to change notification settings - Fork 0
Your First API
Shashank Patil edited this page Jul 26, 2026
·
1 revision
In this guide, you'll create your first API using the Generic SQL API Framework.
Create a new SQL file inside the queries directory.
Example:
queries/customers.sql
SELECT
CustomerID,
CustomerName,
City,
MobileNumber
FROM CustomerTable;Save the file.
Send the following JSON request to the Query API.
{
"query": "customers"
}The framework automatically loads:
queries/customers.sql
and executes the SQL query.
Example:
POST /api/query
Content-Type: application/jsonRequest Body:
{
"query": "customers"
}The framework performs the following steps automatically:
- Receives the JSON request.
- Validates the request.
- Locates the SQL file.
- Builds the SQL statement.
- Executes the query.
- Returns the results as JSON.
Example Response:
{
"success": true,
"rows": [
{
"CustomerID": 1,
"CustomerName": "John Doe",
"City": "Bangalore",
"MobileNumber": "9876543210"
}
]
}Suppose you want to retrieve a specific customer.
SQL:
SELECT *
FROM CustomerTable
WHERE CustomerID = :CustomerID;JSON Request:
{
"query": "customer_by_id",
"parameters": {
"CustomerID": 1001
}
}SQL:
SELECT *
FROM CustomerTable
WHERE City = :City
AND Status = :Status;JSON:
{
"query": "customers",
"parameters": {
"City": "Bangalore",
"Status": "Active"
}
}If the SQL file does not exist:
{
"success": false,
"message": "Query file not found."
}If a required parameter is missing:
{
"success": false,
"message": "Missing required parameter: CustomerID"
}- Keep one SQL query per file.
- Use descriptive query names.
- Use parameterized queries to prevent SQL injection.
- Organize SQL files into folders for larger projects.
- Test queries directly in SQL Server before using them in the framework.
Now that you've created your first API, continue with:
- JSON Request Format
- SQL Query Files
- Validation Engine
- Query Examples
- Advanced Features