Gropius is a Rust toolkit for designing APIs. It's compatible with OpenAPI 3.1.x, but, unlike most toolkits, it lets you generate the spec from the code, instead of the code from the spec:
/// A chair designed by Walter Gropius.
#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
struct Chair {
id: String,
year: u32,
description: String,
}
#[gropius::api(tags = ["chairs"])]
/// Explore chairs designed by Walter Gropius.
trait ChairApi {
/// List chairs by year.
#[endpoint(GET, "/chairs/{year}")]
async fn list_chairs(&self, path: gropius::Path<u16>) -> Result<Vec<Chair>, ApiError>;
/// Get a chair by ID.
#[endpoint(GET, "/chairs/{year}/{id}")]
async fn get_chair(&self, path: gropius::Path<(u64, String)>) -> Result<Widget, ApiError>;
}For more details, head to the docs.
The crate is new and is currently alpha quality. However, it has several distinguishing features compared to similar libraries:
- Integrates with
tower::Serviceandhyperon the server - Integrates with either
reqwestorureqon the client - Supports grouping endpoints into multiple traits, which can then be combined in a single API surface
- Supports OpenAPI 3.1.x, with 3.2.x support planned
Gropius is inspired by and indebted to these libraries, which have a similar approach:
