Meridian Primer

Rocket (Rust) Primer

Rocket is a Rust web framework focused on type safety, ergonomic routing, and async-first request handling. This primer walks you through the minimum viable Rocket service that integrates cleanly with the Meridian ingestion layer, so you can ship a typed HTTP surface in under an hour.

01.Project bootstrap

Start a fresh crate and pin the latest stable Rocket release. Thejsonfeature unlocks the typed body extractor you will use for every Meridian payload.

# Cargo.toml
[package]
name = "meridian-edge"
version = "0.1.0"
edition = "2021"

[dependencies]
rocket = { version = "0.5", features = ["json"] }
serde  = { version = "1", features = ["derive"] }

02.Typed routes

Rocket leans on attribute macros and the request guard pattern. Declare your routes with explicit method + path, return any type that implements Responder, and mount them on a launched instance.

#[macro_use] extern crate rocket;
use rocket::serde::{json::Json, Deserialize, Serialize};

#[derive(Deserialize)] struct Ping { msg: String }
#[derive(Serialize)]   struct Pong { echo: String }

#[post("/echo", data = "<p>")]
fn echo(p: Json<Ping>) -> Json<Pong> {
    Json(Pong { echo: p.msg.clone() })
}

#[launch]
fn rocket() -> _ {
    rocket::build().mount("/", routes![echo])
}

03.Wiring into Meridian

Point your Rocket service at the Meridian gateway by reading the base URL and key from environment. Forward requests with the same JSON shape the gateway expects and you are production-ready. Use Rocket fairings for request logging and per-route auth guards for tenant scoping.

  • Set MERIDIAN_URL + MERIDIAN_KEY via Rocket.toml.
  • Use reqwest with rustls for outbound TLS to the gateway.
  • Stream long completions back through rocket::response::stream.