Skip to main content
Turn a JSON request into a validated Rust model before it reaches your handler. The same model validates the response on the way out.
JSON requestModel validationTyped handler

Install the integration

Enable the axum feature to use Axum 0.8 adapters:
Cargo.toml

Create a validated endpoint

src/main.rs
rydantic::axum::Json<T> reads raw JSON and applies model normalization and validation. It also supports collections such as Json<Vec<User>>. Responses revalidate the model, apply output aliases and exclusions, and set Content-Type: application/json. The complete Axum API is re-exported through rydantic::axum::framework; Router and routing are also available directly.

Handle validation errors

Error bodies use {"detail": [ValidationError, ...]} and preserve field paths, codes, stages, and constraint parameters. Axum’s DefaultBodyLimit applies, and application/*+json content types are supported.

Use asynchronous validators

For asynchronous validators, extract AsyncJson<T> and await output validation explicitly:
Here Account is a model with asynchronous validators, as shown in the asynchronous validation guide. Tokio provides the asynchronous runtime; Axum supplies the HTTP routing and extraction layer.

Keep building

Build a CRUD API

Follow a complete SQLite project with requests and expected responses.

Run service examples

Try the same model with three SQL backends.

Add a database

Connect this endpoint to validated SQL models.

Write async validators

Check application rules at asynchronous boundaries.