Examples

All examples are in the examples/ directory. Build any example:

pranor build examples/<name>.pnr -o demo.exe

By Category

Getting Started

FileDescription
01_scheduler.pnrTimer-based scheduled tasks
02_rest_api.pnrSimple REST API with routes
05_error_handling.pnrTry/catch error handling

HTTP & API

FileDescription
19_rate_limiting.pnrPer-route rate limiting
29_middleware.pnrMiddleware chains
43_request_validation.pnrBody validation with schemas
34_websocket_logging.pnrWebSocket endpoints + structured logging

Database & Cache

FileDescription
07_advanced_features.pnrSQLite + cache + match patterns
08_multi_database.pnrMultiple database connections
24_migrations.pnrDatabase migrations
22_query_hooks.pnrBefore-query hooks

Concurrency & Messaging

FileDescription
03_pubsub_concurrency.pnrPub/sub messaging with spawn
30_async_await.pnrAsync/await patterns
36_channels.pnrGo-style channels
11_concurrent_maps.pnrThread-safe maps

Language Features

FileDescription
25_structs.pnrStructs and methods
28_interfaces_collections.pnrInterfaces + collection methods
32_generics.pnrGeneric functions
46_generic_constraints.pnrConstrained generics (Ordered, Numeric)
33_string_methods.pnrString manipulation
38_destructuring.pnrlet { x, y } = obj
39_optional_chaining.pnruser?.address?.city
40_spread_operator.pnr{ ...defaults, ...overrides }
41_new_features.pnrEnums with values, type aliases

Integration

FileDescription
04_python_binding.pnrPython extern bindings
31_go_packages.pnrImporting Go packages
44_package_usage.pnrUsing serv add packages (uuid)
15_mcp_support.pnrMCP tool definitions

Configuration & Deployment

FileDescription
09_yaml_config.pnrYAML config file loading
37_structured_logging.pnrJSON logging, context loggers
42_config_validation.pnrRequired config validation
45_stdlib_usage.pnrUsing the standard library

Walkthrough: Building a REST API

// 1. Declare infrastructure
server "8080"
database "sqlite://todos.db"

// 2. Setup schema
migration "create_todos" {
    db.query("CREATE TABLE IF NOT EXISTS todos (id INTEGER PRIMARY KEY, title TEXT, done BOOLEAN DEFAULT 0)")
}

// 3. Define routes
route "GET" "/todos" (req) {
    let todos = db.query("SELECT * FROM todos")
    return { "todos": todos }
}

route "POST" "/todos" (req) {
    let errors = validate(req.body, { "title": "required" })
    if errors != nil {
        return { "status": 400, "errors": errors }
    }
    db.query("INSERT INTO todos (title) VALUES (?)", req.body)
    return { "status": 201, "message": "Created" }
}

// 4. Background cleanup
every 1h {
    let count = db.query("DELETE FROM todos WHERE done = 1")
    log.info("Cleaned up done todos")
}

Build and run:

pranor build todo.pnr -o todo.exe
./todo.exe

Test:

curl http://localhost:8080/todos
curl -X POST http://localhost:8080/todos -d '{"title":"Buy milk"}'
curl http://localhost:8080/health