VSR
A Rust toolkit for declaring REST APIs in Rust or .eon and running them through a CLI-first workflow on top of Actix Web and SQLx.
Note: This project is currently very much in progress and under active development. APIs will change, and features are incomplete.
VSR started as a derive-macro shortcut for rapid API prototypes. The project is now centered on full
.eonservice definitions, built-in auth and admin flows, explicit migrations, and a nativevsrruntime that can serve, emit, and build APIs from the same contract.
VSR CLI
The main entry point is the vsr command-line tool. The published crate is vsra; the installed binary is vsr.
Instant schema defined server for REST API with real database connections:
# Create <some_name>.eon file and define the service
# Alternative commands to get started
Core CLI workflows:
vsr init my-apigenerates a local starter project withapi.eon,.env.example,migrations/, and a comment-rich default service contractvsr serve api.eonruns a native server directly from.eonfor the fastest local development loopvsr server expand ...writes the fully expanded Rust module source so you can inspect the compiler output directlyvsr server emit ...exports an inspectable Rust server projectvsr build ...produces a standalone binary plus a<binary>.bundle/runtime bundlevsr openapi ...,vsr docs ...,vsr authz ..., andvsr backup ...generate docs, diagnostics, and deployment guidance from the same service contract
See the full command reference in crates/rest_api_cli/README.md.
Features
- CLI-first workflow: Scaffold, serve, emit, build, inspect, and document services with
vsr - Native
.eonruntime:vsr serve <service.eon>serves the same API shape directly without generating or compiling a Rust project first - Zero-boilerplate REST APIs: Create complete CRUD endpoints with a single derive macro
- Typed write DTOs: The derive macro and
.eonmacro both generateCreateandUpdatepayload types - Compile-time
.eonservices: Generate strongly typed resources and DTOs from a minimal.eonservice file - Migration generation: Generate explicit SQL migrations from
.eonservice definitions - Field validation: Enforce string length and numeric range constraints in generated handlers and OpenAPI
- Stable error envelope: Generated resource handlers return JSON errors with
code,message, and optionalfield - Typed list queries: Generated collection routes support typed
limit,offset,sort,order, exact-matchfilter_<field>params, and paged response envelopes - Built-in authentication: JWT-based authentication with role management
- Role-Based Access Control: Declarative protection for your endpoints with role requirements
- Database Agnostic: Currently defaults to SQLite, with plans to support all SQLx targets
- Relationship Handling: Define foreign keys and nested routes between resources
- Referential Actions: Configure relation delete behavior with
Cascade,Restrict,SetNull, orNoAction
Installation
CLI
Install the vsr command-line tool from crates.io:
If you are working from a checkout of this repository, the workspace defaults to the CLI package,
so a plain root build produces target/release/vsr:
Use cargo build --workspace when you want all workspace crates, or
cargo build -p very_simple_rest when you want only the library package.
Library
You can include this library in your project by adding it as a git dependency in your Cargo.toml:
Note that you need to add the other dependencies aswell
[]
= { = "https://github.com/MatiasHiltunen/very_simple_rest.git" }
= { = "1", = ["derive"] }
= { = "0.7", = ["macros", "runtime-tokio", "sqlite"] }
= "4"
= "0.10"
= "0.4"
Documentation
- CLI tool guide
- .eon reference
- .eon vNext roadmap
- Authorization roadmap
- Backup and replication roadmap
Examples
The repository includes:
examples/template: the current.eon-first starter example used as the reference shape forvsr initexamples/cms: a full contract-first CMS example with a Material studio client and local S3-compatible storageexamples/demo: the older Rust example binary
To run the starter contract example:
To run the CMS example:
To run the Rust demo example from the project root:
Quick Start
use *;
async
Authentication
The library provides these authentication endpoints out of the box:
- POST /api/auth/register - Register a new user
- POST /api/auth/login - Login and get a JWT token
- GET /api/auth/me - Get information about the authenticated account
Built-in auth failures now also use the shared JSON error envelope. For example, invalid login returns:
When you create built-in admin users through vsr create-admin or vsr setup, the CLI now
inspects the built-in auth claim columns and can populate them during admin creation. With legacy
implicit claims, that means numeric columns such as tenant_id, org_id, or
claim_workspace_id. With explicit security.auth.claims, it uses the mapped user table
columns instead, including String and Bool claim types. Interactive flows prompt for those
values, and non-interactive flows accept environment variables named ADMIN_<COLUMN_NAME>, such
as ADMIN_TENANT_ID=1 or ADMIN_IS_STAFF=true.
When security.auth.claims is configured on a .eon service, vsr setup now extends the
built-in auth user table with those mapped columns automatically before admin creation. Manual
claim-column SQL is no longer required for .eon-driven services.
Use that for stable user/session attributes. For permissions, delegated access, and scope-bound
grants, prefer the runtime authorization tables and authorization contract instead of adding
permission state to the built-in auth user row.
For services that expose the built-in auth admin routes, PATCH /api/auth/admin/users/{id} can
also update configured security.auth.claims values on existing users. That makes it possible to
bootstrap claim-scoped examples and policy-heavy services through HTTP instead of direct SQL
updates.
JWT Configuration
Built-in auth now requires an explicit JWT signing configuration before the server starts. The legacy shared-secret path still works:
security: {
auth: {
jwt_secret: { env_or_file: "JWT_SECRET" }
}
}
For new services, prefer the structured JWT block so you can choose an algorithm and rotate keys:
security: {
auth: {
jwt: {
algorithm: EdDSA
active_kid: "2026-04"
signing_key: { env_or_file: "JWT_SIGNING_KEY" }
verification_keys: [
{ kid: "2026-04", key: { env_or_file: "JWT_VERIFYING_KEY" } }
{ kid: "2026-03", key: { env_or_file: "JWT_VERIFYING_KEY_PREVIOUS" } }
]
}
}
}
Supported runtime secret sources still use typed SecretRefs:
- Environment variable or mounted file via
{ env_or_file: "JWT_SIGNING_KEY" } - Explicit file path via
{ file: "/run/secrets/JWT_SIGNING_KEY.pem" } - systemd credential via
{ systemd_credential: "jwt_signing_key" } - External secret contract via
{ external: { provider: "...", locator: "..." } }
The runtime no longer generates a random fallback secret, so tokens remain valid across restarts
and multi-instance deployments only when you provide explicit signing material. For asymmetric
algorithms, prefer PEM files via *_FILE or direct file paths instead of inline env values.
For production, prefer secret files or a secret manager over inline .env values. The current
production-secrets plan is in
docs/production-secrets-roadmap.md.
Example login:
User Management
The library provides two methods for creating admin users:
1. Environment Variables (Non-Interactive)
Set these environment variables before starting your application:
ADMIN_EMAIL=admin@example.com
ADMIN_PASSWORD=securepassword
ADMIN_TENANT_ID=1
After the built-in auth schema has been migrated, ensure_admin_exists can create the first admin
user automatically with these credentials. If the user table also has numeric claim columns such
as tenant_id, org_id, or claim_workspace_id, ensure_admin_exists now reads matching
ADMIN_<COLUMN_NAME> variables and stores them on the admin row too. The CLI uses the same
ADMIN_<COLUMN_NAME> convention for explicit security.auth.claims mappings.
If your app startup already has an explicit AuthSettings value, prefer
auth::ensure_admin_exists_with_settings(&pool, &settings) so admin bootstrap follows the same
configured claim mappings as login and /api/auth/me.
2. CLI Tool (Interactive)
The library includes a CLI tool for managing your API, with specific commands for user management:
# Generate a migration for the built-in auth schema
# Generate the runtime authorization assignment schema used by authz simulation and future policy APIs
# Emit a standalone Rust server project from a bare .eon service
# Build a server binary directly from a bare .eon service
# Setup wizard with interactive prompts
# Production-safe setup: do not write live secrets into `.env`
# Create an admin user
# Create an admin with specific credentials
# Check database status including admin users
# Generate a .env template file
# Generate a production-safe env template
# Generate Infisical Agent/runtime scaffolding from a `.eon` service
# For machine-identity agent flows, prefer adding the Infisical project UUID too
# Validate resolved secret bindings and optional Infisical scaffold files
# Run compiler-facing schema diagnostics
# Render a backend-aware backup/replication plan from a `.eon` service
The CLI tool provides a secure way to set up admin users with password confirmation and validation.
When you run vsr from a directory containing exactly one .eon file, commands such as setup,
create-admin, check-db, and gen-env now auto-discover that service and derive the default
database URL from it.
For .eon services, vsr gen-env now writes a real local Turso encryption key when
database.engine = TursoLocal is in use, and vsr setup now bootstraps local runtime inputs
before database work: it generates or loads .env, can create self-signed dev TLS certs from the
service tls config, and prints the exact paths it generated or reused.
For production, vsr setup --production and vsr gen-env --production switch to template-only
secret handling: they do not write live JWT/database/mail secrets into .env, and setup refuses
to continue when required production secrets are unresolved. The CLI and runtime also honor
DATABASE_URL_FILE when you prefer mounted secret files over inline connection URLs.
For Infisical, vsr secrets infisical scaffold now generates an Infisical Agent config, per-secret
templates, and a runtime.env file with the *_FILE bindings the VSR runtime already understands.
vsr doctor secrets validates the currently resolved bindings and can also verify that the
generated Infisical scaffold directory is complete. See docs/infisical.md.
vsr check now runs compiler-facing diagnostics over .eon or derive-backed schema sources.
The first strict slice focuses on high-confidence issues: TLS file paths that do not exist,
authorization contracts that do not affect generated runtime behavior, unused declared scopes, and
policy, nested-route, exists, and hybrid lookup fields that rely on inferred indexes without an
explicit .eon declaration. It also flags build-artifact misconfigurations such as empty declared
env overrides, binary/bundle path collisions, and resolved cache/output overlaps.
Add --strict to fail the command when any warning is reported.
For detailed instructions on using the CLI tool, see the CLI Tool Documentation.
Server Generation
The CLI can serve a bare .eon service directly, emit an inspectable Actix server project, or
build a compiled binary from the same contract:
# Run the API directly from the .eon service for fast local iteration
# Generate a local Rust project you can inspect and edit
# Build a binary directly from the same .eon file
vsr serve is the fastest development loop. It serves the compiled API surface directly from the
.eon file, including /openapi.json, /docs, static mounts, built-in auth, runtime authz
management routes, compiled database settings, and TLS when configured.
The emitted project includes:
Cargo.tomlwith the required runtime dependenciessrc/main.rswired torest_api_from_eon!- the copied
.eonfile .env.exampleopenapi.jsonmigrations/0000_auth.sqlwith built-in auth enabled by defaultmigrations/0001_service.sql
Built-in auth and account routes are enabled by default for generated servers and documents. Use
--without-auth if your .eon service defines its own user table or if you want to omit the
shared /auth routes and migrations/0000_auth.sql.
vsr build <service.eon> now writes the binary next to the .eon file by default, naming it
after the .eon file stem. For example, vsr build examples/cms/api.eon produces
examples/cms/api and uses examples/cms/.vsr-build/ for its reusable generated-project cache.
If --output points to an existing directory, the binary is placed inside that directory using
the same default name.
The build command also exports the generated runtime assets next to the binary in
<binary>.bundle/, including .env.example, openapi.json, the copied .eon file,
README.md, migrations/, and relative TLS certificate files when they exist at build time.
When runtime.compression.static_precompressed = true, vsr build also generates .br and
.gz companion files for copied static assets inside that bundle.
.eon services can now also declare build artifact locations under build.artifacts, with the
following precedence for each artifact path: explicit CLI override, then a declared env var
override, then the literal .eon path, then the service-relative default. If a build artifact
does not declare an env var in .eon, vsr does not attempt to read one implicitly.
vsr clean --input <service.eon> now resolves and removes that same service-specific build cache.
Without --input or --build-dir, it preserves the legacy fallback of cleaning ./.vsr-build
from the current working directory.
Generated server projects serve the OpenAPI document at /openapi.json and a Swagger UI page at
/docs.
When a .eon service defines static mounts, vsr server emit also copies those directories into
the generated project so the emitted server can serve them without extra setup.
When a .eon service defines security, vsr server emit also applies the compiled JSON body
limits, CORS policy, trusted-proxy handling, auth rate limits, security headers, and built-in
auth token settings automatically in the emitted server.
When a .eon service defines tls, vsr server emit also wires Rustls-based HTTPS with HTTP/2
in the emitted server, defaults BIND_ADDR to 127.0.0.1:8443, and lets you generate local
certificate PEM files with vsr tls self-signed.
vsr server emit also carries the compiled .eon database engine config into the generated
project. SQLite services now default to encrypted database.engine = TursoLocal, using
var/data/<module>.db and TURSO_ENCRYPTION_KEY unless you override it explicitly. You can still
opt back into the legacy runtime path with database.engine.kind = Sqlx.
OpenAPI
You can also render an OpenAPI document directly from either a .eon file or derive-based Rust
sources:
# Generate OpenAPI JSON from a bare .eon service
# Generate the same kind of document from #[derive(RestApi)] resources
# Omit built-in auth and account routes if your service owns the user model
The current generator covers generated resource routes, DTO schemas, nested collection routes, JWT
bearer auth, the /api server base URL, and built-in auth/account routes by default. Use
--without-auth to omit them. In Swagger, login and registration appear under Auth, while the
current-user endpoint appears under Account. Generated server projects reuse the same document.
Collection and nested collection routes also document their typed list query parameters and their
paged response envelopes, including pagination, sorting, cursor pagination, exact-match field
filters, total, next_offset, and next_cursor.
.eon Reference Docs
You can generate a Markdown reference for the full currently supported .eon surface:
The generated document is intended to be precise enough for AI agents and still readable for
humans. The checked-in reference lives at docs/eon-reference.md.
The staged authorization architecture plan lives at docs/authorization-roadmap.md.
Authorization Explain
You can inspect how the current .eon roles and row policies compile into the internal
authorization model:
This is intended as the first correctness-oriented diagnostic step before richer policy features such as simulation and runtime-managed assignments.
You can also simulate one authorization decision against that compiled model:
--claim, --row, and --proposed accept repeated key=value pairs. Values are inferred as
null, bool, i64, or String. Repeated --related-row values use
Resource:key=value,other=value syntax so the simulator can evaluate relation-aware exists
predicates against explicit related rows. --scope accepts ScopeName=value, and repeated
--scoped-assignment values accept permission:Name@Scope=value or
template:Name@Scope=value. --load-runtime-assignments fetches stored assignments for
--user-id from the configured database, using the runtime authz table created by
vsr migrate authz. Runtime scoped assignments are resolved and validated against the static
authorization contract in the simulator. --hybrid-source adds a second, generated-handler
view for item, collection_filter, nested_parent, or create_payload scope derivation when
the resource declares authorization.hybrid_enforcement.
Stored runtime assignments now include created_at, created_by_user_id, and optional
expires_at; expired assignments are ignored by runtime simulation and runtime access checks.
The same persisted runtime-assignment layer is also manageable directly from the CLI:
authz runtime create validates the target permission/template and scope against the static
.eon authorization contract before persisting the assignment. authz runtime evaluate loads
stored assignments for the user and evaluates only the runtime grant layer; it does not run the
static CRUD role and row-policy checks. authz runtime revoke deactivates an assignment by
setting its expiration to the current time without deleting its record, and authz runtime renew
sets a new future expiration. authz runtime history reads the append-only assignment event log,
which now records created, revoked, renewed, and deleted events with actor and optional
reason data.
.eon also now accepts an optional static authorization block for declaring scopes,
permissions, templates, and an opt-in runtime authorization management API. The scope /
permission / template part is still contract-only by itself: it is validated, included in the
compiled authorization model, and shown by vsr authz explain. Request-time behavior changes
only when you explicitly opt into either the management API or hybrid enforcement. The management
API can be enabled explicitly:
authorization: {
management_api: {
mount: "/authz/runtime"
}
scopes: {
Family: {}
}
permissions: {
FamilyRead: {
actions: ["Read"]
resources: ["ScopedDoc"]
scopes: ["Family"]
}
}
}
For generated routes, .eon can also opt into the first hybrid-enforcement slice:
authorization: {
scopes: {
Family: {}
}
permissions: {
FamilyManage: {
actions: ["Create", "Read", "Update", "Delete"]
resources: ["ScopedDoc"]
scopes: ["Family"]
}
}
hybrid_enforcement: {
resources: {
ScopedDoc: {
scope: "Family"
scope_field: "family_id"
scope_sources: {
item: true
collection_filter: true
nested_parent: true
create_payload: true
}
actions: ["Create", "Read", "Update", "Delete"]
}
}
}
}
In this mode, generated GET /resource/{id}, PUT /resource/{id}, and DELETE /resource/{id}
still apply the normal static role checks first. If the static row-policy path denies the row,
the handler can then derive a runtime scope from the stored row, such as Family=42 from
family_id, and consult persisted runtime scoped grants through AuthorizationRuntime.
Generated POST /resource can also opt into the first hybrid create slice, but only when the
configured scope_field is already claim-controlled in policies.create. In that case, the
generated create DTO exposes that one field as an optional fallback, and the handler uses it only
when the claim is missing and a matching runtime scoped Create grant exists for the supplied
scope.
Top-level GET /resource can also use runtime Read grants when the request includes an exact
filter_<scope_field>=... value, and nested collection routes such as
GET /parent/{id}/resource can do the same when scope_sources.nested_parent = true and the
nested parent filter is the configured scope_field. When a POST /resource request creates a
row that is only runtime-readable, the created response can also render that row through the same
hybrid read fallback instead of returning an empty 201.
This is additive only: it does not bypass static role requirements, it still needs one concrete scope per request, and it does not let runtime grants override unrelated create assignments.
Generated .eon modules expose the compiled authorization view through module::authorization()
so manual apps or emitted servers can build custom policy-management and diagnostics surfaces on
top of the same typed model. They also expose module::authorization_runtime(db) and
module::authorization_management(). module::configure(...) now registers the runtime service
as Actix app data so custom handlers can load, persist, and simulate runtime scoped assignments
without duplicating storage logic. When authorization.management_api is enabled in .eon,
generated configure(...) also mounts the runtime management routes automatically at the
configured mount. You can still call module::configure_authorization_management(cfg, db) for an
explicit mount using the same configured path:
POST <mount>/evaluateGET <mount>/assignments?user_id=...GET <mount>/assignment-events?user_id=...POST <mount>/assignmentsPOST <mount>/assignments/{id}/revokePOST <mount>/assignments/{id}/renewDELETE <mount>/assignments/{id}
Those endpoints manage persisted scoped permission/template assignments through the shared
authorization runtime. Assignment records include created_at, created_by_user_id, and an
optional expires_at, and expired assignments are ignored by runtime evaluation. The append-only
assignment event stream records created, revoked, renewed, and deleted events with actor
metadata, and is available from GET <mount>/assignment-events?user_id=.... POST /authz/runtime/evaluate checks which persisted scoped permissions apply to an explicit
resource + action + scope for the current user or an admin-selected user. It still does not
run static role checks, row policies, or create-time assignments, so CRUD enforcement remains
unchanged.
For real custom endpoint enforcement, handlers can inject
web::Data<very_simple_rest::authorization::AuthorizationRuntime> and call
runtime.enforce_runtime_access(&user, "ResourceName", AuthorizationAction::Read, scope).await.
That enforces persisted runtime scoped permissions for the current user, while still leaving
generated CRUD handlers on their existing static authorization path.
Static Files In .eon
Bare .eon services can configure static file serving at the service level:
module: "static_site_api"
static: {
mounts: [
{
mount: "/assets"
dir: "public/assets"
mode: Directory
cache: Immutable
}
{
mount: "/"
dir: "public"
mode: Spa
index_file: "index.html"
fallback_file: "index.html"
cache: NoStore
}
]
}
resources: [
{
name: "Page"
fields: [
{ name: "title", type: "String" }
]
}
]
Supported static mount options:
mount: URL prefix such as/assetsor/dir: directory relative to the.eonfilemode:DirectoryorSpaindex_file: optional directory index file, defaulting toindex.htmlforSpafallback_file: SPA fallback target, defaulting toindex.htmlforSpacache:NoStore,Revalidate, orImmutable
The loader validates that:
- static directories stay under the
.eonservice root - reserved routes such as
/api,/auth,/docs, and/openapi.jsonare not shadowed - SPA fallback only applies to
GETandHEADHTML navigations, not missing asset files - symlinked directories are rejected during emitted-project copying
Database Engine In .eon
Bare .eon services can also define a service-level database engine. For SQLite services, the
default when this block is omitted is:
database: {
engine: {
kind: TursoLocal
path: "var/data/<module>.db"
encryption_key: { env_or_file: "TURSO_ENCRYPTION_KEY" }
}
}
You can still override it explicitly:
database: {
engine: {
kind: TursoLocal
path: "var/data/app.db"
encryption_key: { env_or_file: "TURSO_ENCRYPTION_KEY" }
}
}
Current support:
Sqlx: the legacy runtime path; use this explicitly if you want plain SQLx SQLite for a SQLite.eonserviceTursoLocal: bootstraps a local Turso database file and uses the project runtime database adapter with SQLite-compatible SQLTursoLocal.encryption_key: typed secret ref for the local Turso hex key; the preferred form is{ env_or_file: "TURSO_ENCRYPTION_KEY" }TursoLocal.encryption_key_env: legacy shorthand still accepted for backward compatibility
Current limitation:
- This is still a project-local runtime adapter, not a true upstream SQLx
Anydriver.
Backup And Replication Planning
.eon can now also declare an optional resilience contract under database.resilience. This is a
planning/documentation surface first: it lets vsr explain the intended backup and replication
posture without embedding deployment-specific schedules into the schema.
database: {
engine: {
kind: Sqlx
}
resilience: {
profile: Pitr
backup: {
mode: Pitr
target: S3
verify_restore: true
max_age: "24h"
encryption_key: { env_or_file: "BACKUP_ENCRYPTION_KEY" }
}
replication: {
mode: ReadReplica
read_routing: Explicit
read_url: { env_or_file: "DATABASE_READ_URL" }
max_lag: "30s"
}
}
}
Use:
The first implementation is intentionally conservative:
- it renders backend-aware backup and replication guidance
- it can validate obvious env and connectivity gaps with the doctor commands
vsr replication doctorcan inspect live Postgres/MySQL role signals (pg_is_in_recovery(),read_only) for declared primary/read URLs- it can create and verify snapshot artifacts for SQLite/TursoLocal services
- it can create Postgres/MySQL logical dump artifacts with
pg_dump/mysqldump, falling back to official Docker client images when those tools are not installed locally vsr backup verify-restorecan now restore those Postgres/MySQL dump artifacts into disposable local Docker databases and validate the restored schema- it can push and pull backup artifact directories to S3-compatible storage
- it does not schedule jobs or orchestrate failover
- runtime read-routing is still future work
For S3-compatible providers such as MinIO, pass an endpoint override and path-style requests:
TLS In .eon
Bare .eon services can also enable Rustls-based HTTPS for generated Actix servers:
tls: {
cert_path: "certs/dev-cert.pem"
key_path: "certs/dev-key.pem"
cert_path_env: "TLS_CERT_PATH"
key_path_env: "TLS_KEY_PATH"
}
Notes:
- When
tlsis present, generated servers bind with Rustls and enable HTTP/2 automatically. - Relative certificate paths are resolved from the emitted project directory, or from
<binary>.bundle/for built binaries. vsr tls self-signed --config service.eongenerates compatible local PEM files using those configured paths. With a single.eonfile in the current directory,vsr tls self-signedauto-discovers it.BIND_ADDRdefaults to127.0.0.1:8443for TLS-enabled services.
Security In .eon
Bare .eon services can also define service-level server security defaults:
security: {
requests: {
json_max_bytes: 1048576
}
cors: {
origins: ["http://localhost:3000"]
origins_env: "CORS_ORIGINS"
allow_credentials: true
allow_methods: ["GET", "POST", "OPTIONS"]
allow_headers: ["authorization", "content-type"]
expose_headers: ["x-total-count"]
max_age_seconds: 600
}
trusted_proxies: {
proxies: ["127.0.0.1", "::1"]
proxies_env: "TRUSTED_PROXIES"
}
rate_limits: {
login: { requests: 10, window_seconds: 60 }
register: { requests: 5, window_seconds: 300 }
}
headers: {
frame_options: Deny
content_type_options: true
referrer_policy: StrictOriginWhenCrossOrigin
hsts: {
max_age_seconds: 31536000
include_subdomains: true
}
}
auth: {
issuer: "very_simple_rest"
audience: "public-api"
access_token_ttl_seconds: 3600
}
}
Supported security options:
requests.json_max_bytes: JSON body limit for generated resource and built-in auth routescors.origins: explicit allowed origins, or["*"]when credentials are disabledcors.origins_env: optional comma-separated origin list loaded from an environment variablecors.allow_credentials: emitsAccess-Control-Allow-Credentials: truecors.allow_methods: allowed preflight methods, defaulting to common REST verbs when omittedcors.allow_headers: allowed request headers, defaulting toauthorization,content-type, andacceptcors.expose_headers: response headers exposed to the browsercors.max_age_seconds: optional preflight cache durationtrusted_proxies.proxies: exact proxy IPs whose forwarded headers should be trustedtrusted_proxies.proxies_env: optional comma-separated trusted proxy IP list loaded from envrate_limits.login: built-in auth login rate limit by resolved client IPrate_limits.register: built-in auth registration rate limit by resolved client IPheaders.frame_options:DenyorSameOriginheaders.content_type_options: emitsX-Content-Type-Options: nosniffheaders.referrer_policy: values such asNoReferrerorStrictOriginWhenCrossOriginheaders.hsts: optionalStrict-Transport-Securityconfigurationauth.issuer: built-in auth JWTissclaimauth.audience: built-in auth JWTaudclaimauth.access_token_ttl_seconds: built-in auth token lifetime
Generated .eon modules expose the compiled settings through module::security() and
module::configure_security(...). JWT signing material and other secrets should still resolve
from the runtime environment, mounted files, systemd credentials, or a secret manager, not from
literal values embedded in .eon. The current rate-limit implementation is in-memory and
process-local, so it is a good default for a single binary but not a shared distributed limiter.
Runtime In .eon
.eon services can also define service-level runtime defaults:
runtime: {
compression: {
enabled: true
static_precompressed: true
}
}
Generated .eon modules expose this through module::runtime(). The currently parsed runtime
options are:
compression.enabled: enables dynamic HTTP response compression on emitted servers and can be applied manually withvery_simple_rest::core::runtime::compression_middleware(&module::runtime())compression.static_precompressed: enables.brand.gzcompanion-file lookup for generated static mounts, addsVary: Accept-Encoding, and preserves the existing cache policy when an encoded asset is served
vsr build now generates those companion files into <binary>.bundle/ when this flag is enabled.
vsr server emit still copies the source static directories as-is.
Migrations
Generated REST resources no longer run CREATE TABLE IF NOT EXISTS at startup. For .eon
services, generate explicit SQL and apply it before serving traffic:
# Generate the built-in auth migration
# Generate the runtime authorization assignment migration
# Generate migrations from Rust `#[derive(RestApi)]` resources
# Generate an additive migration between two schema versions
# Inspect a live database against a schema source
# Generate a deterministic migration file from a .eon service
# Verify that the checked-in SQL still matches the .eon schema
# Apply migrations to the configured database
# Or derive the database URL from a bare .eon service, including TursoLocal paths
The generated SQL includes:
CREATE TABLEstatements for each resource- Foreign keys for declared relations
- Indexes for relation fields, direct row-policy fields, and
existstarget fields
Built-in auth now has the same explicit schema path:
vsr migrate authgenerates theusertable migrationvsr migrate authzgenerates the runtime authorization assignment table, including audit and expiry columns used by authz diagnostics and policy-management APIsvsr setupapplies that auth migration before prompting for the first admin userensure_admin_existsno longer creates tables at server startup
Derive-based resources can now use the same flow:
vsr migrate derive --input src --output migrations/...scans Rust sources for#[derive(RestApi)]--exclude-table useravoids colliding with the built-in auth migration when your project also exposesUservsr migrate check-deriveverifies checked-in SQL against the current Rust resource definitions
For additive schema evolution, vsr migrate diff compares two schema sources and emits only:
- new tables
- new indexes
- safe added columns that are nullable or have generated timestamp defaults
It intentionally rejects destructive or ambiguous changes such as removed fields, type changes, required backfilled columns, or new relation columns. Those still require a manual SQL migration.
For live databases, vsr migrate inspect compares the current schema to a .eon file, a Rust
source file, or a Rust source directory and reports missing tables, missing columns, missing
indexes, foreign-key target drift, ON DELETE drift, type/nullability mismatches, and missing
timestamp defaults.
For a larger SQLite benchmark fixture with deep relations and a deterministic seed script, see
examples/sqlite_bench/.
For a policy-heavy .eon example with tenant claims, owner-scoped writes, and self-scoped
resources, see examples/fine_grained_policies/.
For a family-management example that combines relation-aware exists policies, create.require,
runtime templates/scopes, hybrid enforcement, and a same-origin browser SPA, see
examples/family_app/.
For a minimal .eon-only app with built-in auth, owner-scoped todos, admin visibility across all
rows, and a static browser client, see examples/todo_app/.
For a real-world single-.eon example with public catalog discovery, built-in account
management, admin-curated thesis topics, owner-scoped collaboration requests, and a same-origin
browser client, see examples/bridgeboard/.
For a larger editorial example with a Material studio client, built-in auth, local object storage,
and a local S3-compatible upload workflow, see examples/cms/.
RBAC Attributes
Protect your endpoints with declarative role requirements:
This will:
- Allow users with the "user" role to read data
- Restrict update/delete operations to users with the "admin" role
- Return 403 Forbidden if the user lacks the required role
Row Policies
Portable row-level policies can be generated at the macro layer. They work for SQLite too, because the generated handlers enforce them in application code instead of relying on database-native RLS.
For derive-based resources:
This makes the generated handlers:
- Filter reads to rows owned by the authenticated user
- Bind
user.idintouser_idon create - Prevent ownership changes through update payloads
- Return
404for update/delete when the row is outside the caller's scope
The same attribute also supports claim-based scoping and explicit admin bypass control:
This makes the generated handlers:
- Read
tenant_idfrom the JWT claims inUserContext - Force
user_idandtenant_idon create, regardless of request payload - Keep tenant-scoped fields out of generated
Create/UpdateDTOs - Apply the same tenant filter to admin users when
admin_bypass = false
In .eon, read, update, and delete filters can also use boolean composition. A single
policy entry stays as-is, arrays imply all_of, and you can nest all_of, any_of, not, and
exists explicitly. Leaf filters support equality plus is_null / is_not_null checks on
nullable fields. create still supports the legacy flat assignment list, and it can now also use
{ assign, require } so create-time preconditions stay declarative.
policies: {
admin_bypass: false
read: {
any_of: [
"owner_id=user.id"
{ field: "archived_at", is_null: true }
{
all_of: [
"tenant_id=claim.tenant_id"
{ not: "blocked_user_id=user.id" }
]
}
]
}
create: [
"owner_id=user.id"
{ field: "tenant_id", value: "claim.tenant_id" }
]
update: {
any_of: [
"owner_id=user.id"
{ field: "archived_at", is_not_null: true }
]
}
delete: "Owner:owner_id"
}
The first relation-aware form is exists, which compiles to a correlated subquery against another
declared resource:
read: {
exists: {
resource: "FamilyMember"
where: [
{ field: "family_id", equals_field: "family_id" }
{
any_of: [
"user_id=user.id"
"delegate_user_id=user.id"
]
}
]
}
}
That shape is intentionally narrow for now:
existstargets another declared resourcewhereaccepts leaf comparisons plus nestedall_of,any_of, andnotgroups- list entries inside
wherestill implyAND - each condition is either
related_field = user.id/claim.<name>/input.<field>,related_field = row.<current_field>, or a nullableIS NULL/IS NOT NULLcheck
Create-time requirements use the same tree:
create: {
assign: [
"created_by_user_id=user.id"
]
require: {
exists: {
resource: "Family"
where: [
{ field: "id", equals: "input.family_id" }
"owner_user_id=user.id"
]
}
}
}
That lets .eon express bounded onboarding rules such as “you may add a family member only to a
family you own” without falling back to handwritten handlers.
When you use the built-in auth routes, /auth/login now emits numeric claims automatically from
the user row. You can also make those claim names explicit in .eon:
security: {
auth: {
claims: {
tenant_id: { column: "tenant_scope", type: I64 }
workspace_id: "claim_workspace_id"
staff: { column: "is_staff", type: Bool }
plan: String
}
}
}
Supported claim-mapping forms:
tenant_id: I64meansclaim.tenant_idcomes fromuser.tenant_idworkspace_id: "claim_workspace_id"meansclaim.workspace_idcomes fromuser.claim_workspace_idstaff: { column: "is_staff", type: Bool }uses a custom column and non-integer type
If you do not configure security.auth.claims, the legacy implicit behavior still applies:
- Any numeric column ending in
_idbecomes a claim with the same name, such astenant_idororg_id - Any numeric column named
claim_<name>becomes a claim named<name>
That lets claim-scoped policies work without a custom token issuer, as long as your user records
carry the relevant columns. Row policies can now consume explicit I64, String, and Bool
claims when the target resource field uses the matching type. The legacy implicit claim path
remains numeric-only, so undeclared claim.<name> usage is still limited to *_id-style claims.
Policy comparisons are still equality-only today; boolean composition and exists change how
filters combine, not which operators are available. vsr authz simulate can fully evaluate
exists predicates when you provide related rows with repeated --related-row arguments; if you
omit them, the trace stays incomplete and tells you which related resource data is missing.
Relationships
Define relationships between entities:
pub post_id: i64,
This generates nested routes like /api/post/{post_id}/comment automatically.
Relation delete behavior is schema-driven and ends up in the generated foreign key:
CascadeRestrictSetNullNoAction
SetNull is only allowed on nullable foreign-key fields.
Custom relation column renames are not supported. The Rust field name is the database column name.
Validation
Generated Create and Update handlers can enforce field-level validation before SQL execution.
Derive example:
.eon example:
{
name: "Post"
fields: [
{ name: "id", type: I64 }
{
name: "title"
type: String
validate: {
min_length: 3
max_length: 120
}
}
{
name: "score"
type: I64
validate: {
minimum: 1
maximum: 10
}
}
]
}
Supported constraints:
min_lengthandmax_lengthfor string-like fieldsminimumandmaximumfor integer and floating-point fields
These constraints are reflected in generated OpenAPI schemas as minLength, maxLength,
minimum, and maximum.
Error Responses
Generated resource handlers now use a stable JSON error body for validation and common CRUD failures:
The current resource-level envelope fields are:
codemessagefieldfor field-specific validation failures
Generated collection routes also accept typed query parameters:
limitandoffsetfor paginationcursor=<token>for keyset paginationsort=<field>andorder=asc|descfor safe sortingfilter_<field>=...for exact-match filtering on generated resource fields
Per-resource page defaults and caps can be configured from either generation path:
resources: [
{
name: "Post"
list: {
default_limit: 25
max_limit: 100
}
fields: [
{ name: "id", type: I64 }
{ name: "title", type: String }
]
}
]
Collection responses now return a metadata envelope instead of a bare JSON array:
Unknown query keys, invalid typed values, and unsupported combinations such as offset without
limit return the same JSON error envelope with invalid_query or invalid_pagination. When a
resource has max_limit configured, oversized limit values are capped to that maximum rather
than rejected. Cursor tokens are opaque, URL-safe strings; they cannot be combined with offset,
sort, or order, because they already encode the current keyset position and sort direction.
OpenAPI documents expose this as ApiErrorResponse and use it for generated 400, 403, 404,
and 500 resource responses where applicable. Built-in auth routes use the same envelope for
login failures, duplicate registration, and token/authentication failures.
Malformed JSON bodies now also use the same envelope, for example:
Invalid path and query parsing now use the same contract too, with codes like:
invalid_pathinvalid_query
EON Service Macro
You can also generate a typed REST module from a .eon file at compile time:
use *;
rest_api_from_eon!;
async
Minimal .eon schema:
resources: [
{
name: "Post"
roles: {
read: "user"
create: "user"
update: "user"
delete: "user"
}
policies: {
admin_bypass: false
read: [
"user_id=user.id"
{ field: "tenant_id", equals: "claim.tenant_id" }
]
create: [
"user_id=user.id"
{ field: "tenant_id", value: "claim.tenant_id" }
]
update: [
"user_id=user.id"
{ field: "tenant_id", equals: "claim.tenant_id" }
]
delete: { field: "tenant_id", equals: "claim.tenant_id" }
}
fields: [
{ name: "id", type: I64 }
{ name: "title", type: String }
{ name: "content", type: String }
{ name: "user_id", type: I64 }
{ name: "created_at", type: String }
{ name: "updated_at", type: String }
]
}
]
Relations in .eon support the same delete actions:
{
name: "Comment"
fields: [
{ name: "id", type: I64 }
{
name: "post_id"
type: I64
relation: {
references: "post.id"
nested_route: true
on_delete: Cascade
}
}
{ name: "body", type: String }
]
}
This generates:
blog_api::Postblog_api::PostCreateblog_api::PostUpdateblog_api::configure
The workspace uses the eon crate for parsing. For formatting .eon files, install the external formatter:
Roadmap
- Support for all SQLx database backends
- More flexible role definitions
- Custom validation rules
- Richer OpenAPI response metadata and more detailed validation/error schemas
Contributions
Contributions are welcome! Feel free to submit issues and pull requests.
AI Assistance
This library has been built with assistance from OpenAI's o4 and Anthropic's Claude 3.5 Sonnet.
License
MIT