This page provides practical examples of common Eden-MDBS operations.
# Login with username and password
curl http://{host}:8000/api/v1/auth/login \
-u admin@company.com:your_password \
-X POST
# Response: {"token": "eyJhbGciOiJIUzI1NiIs..."}
# Save token for subsequent requests
export TOKEN="eyJhbGciOiJIUzI1NiIs..."curl http://{host}:8000/api/v1/auth/refresh \
-H "Authorization: Bearer $TOKEN" \
-X POSTcurl http://{host}:8000/api/v1/endpoints \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $TOKEN" \
-d '{
"id": "main_db",
"kind": "Postgres",
"config": {
"write_conn": {
"url": "postgresql://user:password@localhost:5432/myapp"
}
}
}'curl http://{host}:8000/api/v1/endpoints \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $TOKEN" \
-d '{
"id": "cache",
"kind": "Redis",
"config": {
"write_conn": {
"url": "redis://localhost:6379"
}
}
}'curl http://{host}:8000/api/v1/endpoints \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $TOKEN" \
-d '{
"id": "documents",
"kind": "Mongo",
"config": {
"write_conn": {
"url": "mongodb://user:password@localhost:27017/myapp"
}
}
}'curl http://{host}:8000/api/v1/endpoints \
-H "Authorization: Bearer $TOKEN"# Simple query
curl http://{host}:8000/api/v1/endpoints/main_db/read \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $TOKEN" \
-d '{"query": "SELECT * FROM users LIMIT 10"}'
# Parameterized query
curl http://{host}:8000/api/v1/endpoints/main_db/read \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $TOKEN" \
-d '{
"query": "SELECT * FROM users WHERE status = $1 AND role = $2",
"params": ["active", "admin"]
}'# INSERT
curl http://{host}:8000/api/v1/endpoints/main_db/write \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $TOKEN" \
-d '{
"query": "INSERT INTO users (name, email) VALUES ($1, $2) RETURNING id",
"params": ["John Doe", "john@example.com"]
}'
# UPDATE
curl http://{host}:8000/api/v1/endpoints/main_db/write \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $TOKEN" \
-d '{
"query": "UPDATE users SET status = $1 WHERE id = $2",
"params": ["inactive", 123]
}'
# DELETE
curl http://{host}:8000/api/v1/endpoints/main_db/write \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $TOKEN" \
-d '{
"query": "DELETE FROM sessions WHERE expires_at < NOW()"
}'# Find documents
curl http://{host}:8000/api/v1/endpoints/documents/read \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $TOKEN" \
-d '{
"collection": "products",
"operation": "find",
"filter": {"category": "electronics", "price": {"$lt": 500}},
"options": {"limit": 10, "sort": {"price": 1}}
}'
# Insert document
curl http://{host}:8000/api/v1/endpoints/documents/write \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $TOKEN" \
-d '{
"collection": "products",
"operation": "insertOne",
"document": {
"name": "Wireless Mouse",
"category": "electronics",
"price": 29.99
}
}'# SET
curl http://{host}:8000/api/v1/endpoints/cache/write \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $TOKEN" \
-d '{
"command": "SET",
"args": ["session:user123", "{\"id\":123,\"role\":\"admin\"}", "EX", "3600"]
}'
# GET
curl http://{host}:8000/api/v1/endpoints/cache/read \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $TOKEN" \
-d '{
"command": "GET",
"args": ["session:user123"]
}'
# DELETE
curl http://{host}:8000/api/v1/endpoints/cache/write \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $TOKEN" \
-d '{
"command": "DEL",
"args": ["session:user123"]
}'curl http://{host}:8000/api/v1/iam/users \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $TOKEN" \
-d '{
"username": "developer@company.com",
"password": "SecurePass123!",
"description": "Backend Developer",
"access_level": "Write"
}'curl http://{host}:8000/api/v1/iam/users/developer@company.com \
-H "Authorization: Bearer $TOKEN"curl http://{host}:8000/api/v1/iam/users/developer@company.com \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $TOKEN" \
-X PATCH \
-d '{
"description": "Senior Backend Developer",
"access_level": "Admin"
}'curl http://{host}:8000/api/v1/iam/rbac/endpoints/subjects \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $TOKEN" \
-d '{
"subjects": [
["developer@company.com", "Write"],
["analyst@company.com", "Read"]
]
}'# Check your own permissions on an endpoint
curl http://{host}:8000/api/v1/iam/rbac/endpoints/main_db/subjects \
-H "Authorization: Bearer $TOKEN"
# Check all permissions for an endpoint (Admin only)
curl http://{host}:8000/api/v1/iam/rbac/endpoints/main_db \
-H "Authorization: Bearer $TOKEN"curl http://{host}:8000/api/v1/iam/rbac/endpoints/main_db/subjects/developer@company.com \
-H "Authorization: Bearer $TOKEN" \
-X DELETEcurl http://{host}:8000/api/v1/templates \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $TOKEN" \
-d '{
"id": "get_user_orders",
"description": "Get orders for a user with pagination",
"template": {
"endpoint_uuid": "YOUR_ENDPOINT_UUID",
"kind": "Read",
"template": {
"query": "SELECT * FROM orders WHERE user_id = {{user_id}} ORDER BY created_at DESC LIMIT {{limit}} OFFSET {{offset}}",
"params": ["{{user_id}}", "{{limit}}", "{{offset}}"]
},
"endpoint_kind": "Postgres"
}
}'curl http://{host}:8000/api/v1/templates/get_user_orders \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $TOKEN" \
-X POST \
-d '{
"user_id": 123,
"limit": 10,
"offset": 0
}'curl http://{host}:8000/api/v1/templates/get_user_orders/render \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $TOKEN" \
-X POST \
-d '{
"user_id": 123,
"limit": 10,
"offset": 0
}'curl http://{host}:8000/api/v1/endpoints/main_db/transaction \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $TOKEN" \
-d '{
"operations": [
{
"query": "UPDATE accounts SET balance = balance - $1 WHERE id = $2",
"params": [100.00, 1]
},
{
"query": "UPDATE accounts SET balance = balance + $1 WHERE id = $2",
"params": [100.00, 2]
},
{
"query": "INSERT INTO transfers (from_id, to_id, amount) VALUES ($1, $2, $3)",
"params": [1, 2, 100.00]
}
]
}'curl http://{host}:8000/api/v1/organizations \
-H "Authorization: Bearer $TOKEN"curl http://{host}:8000/api/v1/organizations \
-H "Authorization: Bearer $TOKEN" \
-H "X-Eden-Verbose: true"Here's a complete example of setting up and using Eden:
#!/bin/bash
HOST="your-eden-host"
ORG_TOKEN="your_organization_creation_token"
# 1. Create organization (one-time setup)
curl http://$HOST:8000/api/v1/new \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $ORG_TOKEN" \
-d '{
"id": "my_company",
"super_admins": [{"username": "admin", "password": "AdminPass123!"}]
}'
# 2. Login as admin
TOKEN=$(curl -s http://$HOST:8000/api/v1/auth/login \
-u admin:AdminPass123! \
-X POST | jq -r '.token')
# 3. Create an endpoint
curl http://$HOST:8000/api/v1/endpoints \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $TOKEN" \
-d '{
"id": "app_db",
"kind": "Postgres",
"config": {
"write_conn": {"url": "postgresql://user:pass@db:5432/app"}
}
}'
# 4. Create a user
curl http://$HOST:8000/api/v1/iam/users \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $TOKEN" \
-d '{
"username": "dev@company.com",
"password": "DevPass123!",
"access_level": "Write"
}'
# 5. Grant endpoint access to user
curl http://$HOST:8000/api/v1/iam/rbac/endpoints/subjects \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $TOKEN" \
-d '{"subjects": [["dev@company.com", "Write"]]}'
# 6. User can now query the endpoint
DEV_TOKEN=$(curl -s http://$HOST:8000/api/v1/auth/login \
-u dev@company.com:DevPass123! \
-X POST | jq -r '.token')
curl http://$HOST:8000/api/v1/endpoints/app_db/read \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $DEV_TOKEN" \
-d '{"query": "SELECT * FROM users LIMIT 5"}'