Skip to main content

route

Attribute Macro route 

Source
#[route]
Expand description

Annotate an Axum handler with explicit HTTP method and path.

This is the canonical syntax for specifying both method and path explicitly. The function remains a valid Axum handler with metadata registered for contract generation and router discovery.

§Syntax

#[rorpc::route(method = "POST", path = "/planet/list")]
async fn list_planets(State(db): State<Db>) -> Json<Vec<Planet>> {
    Json(db.list().await)
}

§Arguments

  • method — HTTP method string ("GET", "POST", etc.), normalized to uppercase. Required.
  • path — Route path string (e.g. "/planet/list"). Required.
  • data — String literal naming the SSE data payload type for streaming handlers (e.g. "StreamEvent"). Optional.

§For Shorthand Syntax

Consider using method-specific macros for brevity:

  • #[rorpc::get("/path")]
  • #[rorpc::post("/path")]
  • #[rorpc::put("/path")]
  • #[rorpc::patch("/path")]
  • #[rorpc::delete("/path")]