Examples & Use Cases
Real-world examples demonstrating TON's capabilities.
Configuration Files
Application Configuration
{(appConfig)
name = "MyApplication",
version = "1.2.0",
environment = "production",
database = {(dbConfig)
host = "localhost",
port = 5432,
name = "myapp_prod",
ssl = true,
maxConnections = 100
},
redis = {(cacheConfig)
host = "localhost",
port = 6379,
ttl = 3600
},
features = {
authentication = true,
rateLimit = {
enabled = true,
maxRequests = 1000,
windowMs = 60000
}
}
}
API Documentation
{(apiEndpoint)
path = "/api/users/{id}",
method = "GET",
description = """
Retrieve a user by their ID.
Returns the user object with profile information.
""",
parameters = [
{(param)
name = "id",
type = "integer",
required = true,
description = "User ID"
}
],
response = '''
{
"id": 123,
"name": "John Doe",
"email": "[email protected]",
"createdAt": "2024-01-15T10:30:00Z"
}
''',
examples = {
curl = "curl -X GET https://api.example.com/api/users/123",
javascript = """
const response = await fetch('/api/users/123');
const user = await response.json();
"""
}
}
Database Schemas
{(databaseSchema)
name = "user_management",
version = "1.0.0",
tables = [
{(table)
name = "users",
columns = [
{(column) name = "id", type = "SERIAL", primaryKey = true},
{(column) name = "email", type = "VARCHAR(255)", unique = true},
{(column) name = "created_at", type = "TIMESTAMP", default = "NOW()"}
],
indexes = [
{(index) name = "idx_email", columns = ["email"]},
{(index) name = "idx_created", columns = ["created_at"]}
]
}
],
migrations = '''
ALTER TABLE users ADD COLUMN last_login TIMESTAMP;
CREATE INDEX idx_last_login ON users(last_login);
'''
}
Test Data
{(testFixture)
users = [
{(user)
id = 1,
name = "Alice",
email = "[email protected]",
roles = |admin|user|,
metadata = {
lastLogin = "2024-03-15T10:00:00Z",
loginCount = 42
}
},
{(user)
id = 2,
name = "Bob",
email = "[email protected]",
roles = |user|,
metadata = null
}
],
config = {
testMode = true,
mockServices = ["email", "payment"],
timeout = 5000
}
}
Docker Compose Configuration
{(dockerCompose)
version = "3.8",
services = {
web = {(service)
image = "nginx:alpine",
ports = ["80:80", "443:443"],
volumes = [
"./nginx.conf:/etc/nginx/nginx.conf",
"./ssl:/etc/ssl"
],
dependsOn = ["app"]
},
app = {(service)
build = ".",
environment = {
NODE_ENV = "production",
DATABASE_URL = "postgresql://user:pass@db:5432/myapp"
},
ports = ["3000:3000"]
},
db = {(service)
image = "postgres:15",
environment = {
POSTGRES_DB = "myapp",
POSTGRES_USER = "user",
POSTGRES_PASSWORD = "password"
},
volumes = ["postgres_data:/var/lib/postgresql/data"]
}
},
volumes = {
postgres_data = {}
}
}