Thanks to visit codestin.com
Credit goes to github.com

Skip to content

v0.4.0

Choose a tag to compare

@arferreira arferreira released this 12 Feb 21:48
· 257 commits to main since this release

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 changes

Middleware

  • 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-cli

Thanks to @juv, @ShiraiEd, and @uemuradevexe for their contributions to this release.