Every Rapina handler is an async function annotated with a route macro. Here's the simplest one:
#[public]
#[get("/")]
async fn hello() -> &'static str {
"Hello, Rapina!"
}The #[public] attribute makes this endpoint accessible without authentication — by default, all Rapina routes require JWT auth. The #[get("/")] macro registers it as a GET route at the root path.
Modify the code to:
/helloSerialize and JsonSchema derivesJson<T> response with a name field set to "World"You'll need a struct like HelloResponse with a name: String field, and the handler should return Json(HelloResponse { ... }).Show answer
use rapina::prelude::*;
#[derive(Serialize, JsonSchema)]
struct HelloResponse {
name: String,
}
#[public]
#[get("/hello")]
async fn hello() -> Json<HelloResponse> {
Json(HelloResponse {
name: "World".into(),
})
}