This reference covers the APIs for managing templates in Eden-MDBS.
Templates are reusable, parameterized database operations. They use Handlebars-style syntax for variable substitution and can be executed with different parameters.
Get all templates in your organization.
GET /api/v1/templates
Authorization: Bearer <token>curl http://{host}:8000/api/v1/templates \
-H "Authorization: Bearer $TOKEN"{
"status": "success",
"data": [
{
"id": "get_user",
"uuid": "550e8400-e29b-41d4-a716-446655440000"
},
{
"id": "insert_order",
"uuid": "550e8400-e29b-41d4-a716-446655440001"
}
]
}Get templates updated since a specific timestamp.
GET /api/v1/templates/updated
Content-Type: text/plain
Authorization: Bearer <token>Body: ISO 8601 timestamp string
Create a new template.
POST /api/v1/templates
Content-Type: application/json
Authorization: Bearer <token>| Field | Type | Required | Description |
|---|---|---|---|
id | string | Yes | Unique template identifier |
endpoint | string | Yes | Target endpoint for this template |
query | string | Yes | Query with Handlebars placeholders |
fields | array | No | Field definitions for parameters |
description | string | No | Template description |
curl http://{host}:8000/api/v1/templates \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $TOKEN" \
-d '{
"id": "get_user_by_id",
"endpoint": "postgres_main",
"query": "SELECT * FROM users WHERE id = {{user_id}}",
"fields": [
{
"name": "user_id",
"type": "integer",
"required": true
}
],
"description": "Fetch a user by their ID"
}'{
"status": "success",
"data": "Template created successfully"
}Get details of a specific template.
GET /api/v1/templates/{template}
Authorization: Bearer <token>| Parameter | Type | Description |
|---|---|---|
template | string | Template identifier |
curl http://{host}:8000/api/v1/templates/get_user_by_id \
-H "Authorization: Bearer $TOKEN"{
"status": "success",
"data": {
"id": "get_user_by_id",
"uuid": "550e8400-e29b-41d4-a716-446655440000",
"endpoint": "postgres_main",
"query": "SELECT * FROM users WHERE id = {{user_id}}",
"fields": [
{
"name": "user_id",
"type": "integer",
"required": true
}
],
"description": "Fetch a user by their ID",
"created_at": "2024-01-15T10:30:00Z",
"updated_at": "2024-01-15T10:30:00Z"
}
}Run a template with provided parameters.
POST /api/v1/templates/{template}
Content-Type: application/json
Authorization: Bearer <token>| Parameter | Type | Description |
|---|---|---|
template | string | Template identifier |
JSON object containing template parameter values.
curl http://{host}:8000/api/v1/templates/get_user_by_id \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $TOKEN" \
-d '{
"user_id": 12345
}'{
"status": "success",
"data": [
{
"id": 12345,
"name": "John Doe",
"email": "john@example.com",
"created_at": "2024-01-10T08:00:00Z"
}
]
}Preview the rendered query without executing it.
POST /api/v1/templates/{template}/render
Content-Type: application/json
Authorization: Bearer <token>curl http://{host}:8000/api/v1/templates/get_user_by_id/render \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $TOKEN" \
-d '{
"user_id": 12345
}'{
"status": "success",
"data": {
"query": "SELECT * FROM users WHERE id = 12345",
"endpoint": "postgres_main"
}
}Update an existing template.
PATCH /api/v1/templates/{template}
Content-Type: application/json
Authorization: Bearer <token>| Field | Type | Required | Description |
|---|---|---|---|
query | string | No | Updated query |
fields | array | No | Updated field definitions |
description | string | No | Updated description |
curl http://{host}:8000/api/v1/templates/get_user_by_id \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $TOKEN" \
-X PATCH \
-d '{
"query": "SELECT id, name, email FROM users WHERE id = {{user_id}}",
"description": "Fetch basic user info by ID"
}'{
"status": "success",
"data": "Template updated successfully"
}Remove a template.
DELETE /api/v1/templates/{template}
Authorization: Bearer <token>curl http://{host}:8000/api/v1/templates/get_user_by_id \
-H "Authorization: Bearer $TOKEN" \
-X DELETE{
"status": "success",
"data": "Template deleted successfully"
}Templates support the following field types:
| Type | Description |
|---|---|
string | Text value |
integer | Whole number |
float | Decimal number |
boolean | True/false value |
array | List of values |
object | Nested JSON object |
Templates use Handlebars-style placeholders:
SELECT * FROM users WHERE name = '{{name}}'SELECT * FROM orders
WHERE 1=1
{{#if status}}
AND status = '{{status}}'
{{/if}}INSERT INTO tags (name) VALUES
{{#each tags}}
('{{this}}'){{#unless @last}},{{/unless}}
{{/each}}| Operation | Required Access |
|---|---|
| List templates | Read |
| Get template | Read |
| Create template | Admin |
| Execute template | Read |
| Render template | Read |
| Update template | Admin |
| Delete template | Admin |
{
"error": "Not Found",
"message": "Template 'get_user_by_id' does not exist"
}{
"error": "Bad Request",
"message": "Required field 'user_id' is missing"
}{
"error": "Bad Request",
"message": "Field 'user_id' must be an integer"
}{
"error": "Bad Request",
"message": "Failed to render template: invalid syntax at position 45"
}