Crate rustapi_core

Crate rustapi_core 

Source
Expand description

§RustAPI Core

Core library providing the foundational types and traits for RustAPI.

This crate provides the essential building blocks for the RustAPI web framework:

§Quick Start

use rustapi_core::{RustApi, get, Json};
use serde::Serialize;

#[derive(Serialize)]
struct Message {
    text: String,
}

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

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
    RustApi::new()
        .route("/", get(hello))
        .run("127.0.0.1:8080")
        .await
}

§Feature Flags

  • metrics - Enable Prometheus metrics middleware
  • cookies - Enable cookie parsing extractor
  • test-utils - Enable testing utilities like TestClient
  • swagger-ui - Enable Swagger UI documentation endpoint

§Note

This crate is typically not used directly. Use rustapi-rs instead for the full framework experience with all features and re-exports.

Re-exports§

pub use middleware::BodyLimitLayer;
pub use middleware::RequestId;
pub use middleware::RequestIdLayer;
pub use middleware::TracingLayer;
pub use middleware::DEFAULT_BODY_LIMIT;
pub use sse::Sse;
pub use sse::SseEvent;
pub use stream::StreamBody;

Modules§

middleware
Middleware infrastructure for RustAPI
path_validation
Route path validation utilities
sse
Server-Sent Events (SSE) response types for RustAPI
stream
Streaming response types for RustAPI

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
ClientIp
Client IP address extractor
Created
201 Created response wrapper
Extension
Extension extractor
HandlerService
Wrapper to convert a Handler into a tower Service
HeaderValue
Single header value extractor
Headers
Headers extractor
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
WithStatus
Generic wrapper for returning a response with a custom status code.

Enums§

Environment
Environment configuration for error handling behavior

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_environment
Get the current environment (cached)
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