v0.4.0
This release brings database support, better testing tools, and a bunch of middleware we've been missing.
Database Integration
The big one. You can now define your schema declaratively and get SeaORM entities generated:
rapina::schema! {
User {
#[unique]
email: String,
posts: Vec<Post>,
}
Post {
title: String,
content: Text,
author: User, // generates author_id foreign key
}
}Relationships are inferred from types. Vec<Post> is has_many, User is belongs_to. Optional relationships use Option<User>. Timestamps are automatic but can be disabled with #[timestamps(none)].
Database connection via the Db extractor:
#[get("/posts")]
async fn list_posts(db: Db) -> Result<Json<Vec<Post>>> {
let posts = Post::find().all(db.conn()).await?;
Ok(Json(posts))
}Enable with features = ["postgres"] (or mysql, sqlite).
Testing
New rapina test command with coverage support:
rapina test # run tests
rapina test --coverage # with coverage report
rapina test --watch # re-run on file changesMiddleware
- Rate limiting - Token bucket algorithm, configurable per-route
- Response compression - gzip/brotli support
- CORS - Configurable origins, methods, headers
- Cookie extractor - Typed cookie access in handlers
Other Changes
- Fixed variable shadowing in route macros
- Modular API grouping with
Router::group() - Better error messages across the board
Upgrade
rapina = "0.4.0"If you're using the CLI:
cargo install rapina-cliThanks to @juv, @ShiraiEd, and @uemuradevexe for their contributions to this release.