Skip to main content

Crate rust_api

Crate rust_api 

Source
Expand description

RustAPI: FastAPI-inspired REST framework for Rust

RustAPI brings the developer experience of FastAPI and NestJS to Rust, with automatic OpenAPI generation, built-in validation, and dependency injection.

§Features

  • Route Macros: Define endpoints with #[get], #[post], etc.
  • Dependency Injection: Type-safe DI container for services
  • Type-Driven: Leverage Rust’s type system for validation and docs
  • Zero-Cost: Built on Axum and Tokio for production performance

§Quick Start

use rust_api::prelude::*;

#[get("/users/{id}")]
async fn get_user(Path(id): Path<String>) -> Json<User> {
    // handler code
}

#[tokio::main]
async fn main() {
    let app = Router::new()
        .route(__get_user_route, routing::get(get_user));

    RustAPI::new(app)
        .port(3000)
        .serve()
        .await
        .unwrap();
}

§Examples

See the examples/ directory for complete working examples:

  • basic-api: Complete example with controllers, services, and DI

Re-exports§

pub use di::Container;
pub use di::Injectable;
pub use app::App;
pub use error::Error;
pub use error::Result;
pub use server::RustAPI;
pub use router::Router;
pub use router::RouterExt;

Modules§

app
Application builder for rust-api framework
di
Dependency Injection Container
error
Error types for rust-api framework
prelude
Prelude module for convenient imports
router
Router utilities for RustAPI framework
routing
server
Server runtime for RustAPI framework

Structs§

CorsLayer
Layer that applies the Cors middleware which adds headers for CORS.
Json
JSON Extractor / Response.
Path
Extractor that will get captures from the URL and parse them using serde.
Query
Extractor that deserializes query strings into some type.
State
Extractor for state.
StatusCode
An HTTP status code (status-code in RFC 9110 et al.).
TraceLayer
Layer that adds high level tracing to a Service.

Traits§

Deserialize
A data structure that can be deserialized from any data format supported by Serde.
IntoResponse
Trait for generating responses.
Serialize
A data structure that can be serialized into any data format supported by Serde.

Type Aliases§

Response
Type alias for http::Response whose body type defaults to Body, the most common body type used with axum.

Attribute Macros§

delete
Define a DELETE route handler
get
Define a GET route handler
patch
Define a PATCH route handler
post
Define a POST route handler
put
Define a PUT route handler

Derive Macros§

Deserialize
Serialize