Rocket Contrib
01 / 02

Rocket Contrib Fundamentals: JSON, Databases & Templating

Rocket Contrib: JSON, Databases & Templating

Rocket Contrib was a companion crate to the core Rocket framework, bundling officially-supported extensions -- JSON serialization, database connection pooling, template rendering, and static file serving -- that weren't part of Rocket's minimal core.

JSON Support

use rocket_contrib::json::Json;

#[get("/users/<id>")]
fn get_user(id: u32) -> Json<User> {
    Json(find_user(id))
}

// Later folded more directly into Rocket's own core crate
// in subsequent framework versions

Database Connection Pooling

Rocket Contrib provided database integration helpers, commonly wrapping connection-pooling libraries (like r2d2) to make managing database connections more convenient within a request's lifecycle.

Templating

Integration with templating engines (Tera, Handlebars) let a Rocket application render dynamic server-side HTML by passing data into template files -- alongside JSON, since most real applications need to serve both API responses and rendered pages.

Selective Feature Flags

[dependencies.rocket_contrib]
version = "0.4"
default-features = false
features = ["json"]

# Enabling only the specific features actually needed
# keeps compile times and the dependency tree smaller

Keep your own version of these notes — editable, searchable, and organised by your stack.

Start free