20 minutesAxum → validated model → SQLite → JSON
1. Follow one model through the service
TheUser model derives both Model and SqlModel. The first supplies parsing and output validation. The second supplies SQL metadata, migrations and CRUD operations.
name is trimmed, length-checked and unique. age must be between 18 and 120. SQLite supplies an ID when id is omitted. User::migrate(&pool) creates the table before the HTTP listener starts.
Complete runnable service
Complete runnable service
crates/rydantic/examples/sqlite_api.rs
Json<User> validates before create executes. The handler calls insert and returns the stored row. That response is validated again by Rydantic’s Json adapter.
2. Run the in-process check
3. Start the server
http://127.0.0.1:3000, backed by a fresh in-memory database. In another terminal, create a user:
4. Reject invalid input
name and age in the detail array. No row is inserted. Check the list:
Ada again returns 409 Conflict because the database enforces the unique name. Fetching a missing ID returns 404 Not Found.
5. Update and delete a row
Use the ID returned by the create request. For ID1:
Ctrl-C.
6. Keep data between restarts
Choose a new local database file:Account, inserts a row, previews a rename and two added fields, then applies the plan. Assertions check that the old name survives, enabled is backfilled, and a second migration has no work.
Complete model-to-model migration
Complete model-to-model migration
crates/rydantic/examples/automatic_migrations.rs
Next: build a typed agent
Apply a Rust contract to an AI result.
Use PostgreSQL or MySQL
Run the same API with an independent SQL driver.