Skip to main content

Crate fastapi_macros

Crate fastapi_macros 

Source
Expand description

Procedural macros for fastapi_rust.

This crate provides the following macros:

  • Route macros: #[get], #[post], #[put], #[delete], #[patch], #[head], #[options]
  • #[derive(Validate)] for compile-time validation
  • #[derive(JsonSchema)] for OpenAPI schema generation

§Role In The System

fastapi-macros is the compile-time glue that keeps the runtime minimal. It analyzes handler signatures, generates route registration metadata, and enforces validation/schema rules without any runtime reflection. The emitted code targets types from fastapi-core and fastapi-openapi, and is re-exported by the fastapi facade crate for user ergonomics.

§Example

use fastapi::prelude::*;

#[get("/items/{id}")]
async fn get_item(cx: &Cx, id: Path<i64>) -> Json<Item> {
    // ...
}

Attribute Macros§

delete
Mark a function as a DELETE handler.
get
Mark a function as a GET handler.
head
Mark a function as a HEAD handler.
options
Mark a function as an OPTIONS handler.
patch
Mark a function as a PATCH handler.
post
Mark a function as a POST handler.
put
Mark a function as a PUT handler.

Derive Macros§

JsonSchema
Derive JSON Schema for OpenAPI.
Validate
Derive validation for a struct.