Crate rustapi_rs

Crate rustapi_rs 

Source
Expand description

§RustAPI

A FastAPI-like web framework for Rust.

RustAPI combines Rust’s performance and safety with FastAPI’s “just write business logic” approach. It provides automatic OpenAPI documentation, declarative validation, and a developer-friendly experience.

§Quick Start

use rustapi_rs::prelude::*;

#[derive(Serialize)]
struct Hello {
    message: String,
}

async fn hello() -> Json<Hello> {
    Json(Hello {
        message: "Hello, World!".to_string(),
    })
}

#[tokio::main]
async fn main() -> Result<()> {
    RustApi::new()
        .route("/", get(hello))
        .run("127.0.0.1:8080")
        .await
}

§Features

  • DX-First: Minimal boilerplate, intuitive API
  • Type-Safe: Compile-time route and schema validation
  • Auto Documentation: OpenAPI + Swagger UI out of the box
  • Declarative Validation: Pydantic-style validation on structs
  • Batteries Included: JWT, CORS, rate limiting (optional features)

Modules§

prelude
Prelude module - import everything you need with use rustapi_rs::prelude::*

Macros§

route
Helper macro to create a Route from a handler with RouteHandler trait

Structs§

ApiError
Standard API error type
Body
Raw body bytes extractor
Created
201 Created response wrapper
HandlerService
Wrapper to convert a Handler into a tower Service
Html
HTML response wrapper
Json
JSON body extractor
MethodRouter
HTTP method router for a single path
NoContent
204 No Content response
Path
Path parameter extractor
Query
Query string extractor
Redirect
Redirect response
Request
HTTP Request wrapper
Route
Represents a route definition that can be registered with .mount()
Router
Main router
RustApi
Main application builder for RustAPI
State
State extractor
ValidatedJson
Validated JSON body extractor

Traits§

FromRequest
Trait for extracting data from the full request (including body)
FromRequestParts
Trait for extracting data from request parts (headers, path, query)
Handler
Trait representing an async handler function
IntoResponse
Trait for types that can be converted into an HTTP response
RouteHandler
Trait for handlers with route metadata (generated by #[rustapi::get], etc.)

Functions§

delete
Create a DELETE route handler
delete_route
Create a DELETE route
get
Create a GET route handler
get_route
Create a GET route
patch
Create a PATCH route handler
patch_route
Create a PATCH route
post
Create a POST route handler
post_route
Create a POST route
put
Create a PUT route handler
put_route
Create a PUT route

Type Aliases§

Response
HTTP Response type
Result
Result type alias for RustAPI operations

Attribute Macros§

delete
DELETE route handler macro
description
Description macro for detailed endpoint description in OpenAPI documentation
get
GET route handler macro
main
Main entry point macro for RustAPI applications
patch
PATCH route handler macro
post
POST route handler macro
put
PUT route handler macro
summary
Summary macro for endpoint summary in OpenAPI documentation
tag
Tag macro for grouping endpoints in OpenAPI documentation