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:
- Application Builder:
RustApi- The main entry point for building web applications - Routing:
Router,get,post,put,patch,delete- HTTP routing primitives - Extractors:
Json,Query,Path,State,Body,Headers- Request data extraction - Responses:
IntoResponse,Created,NoContent,Html,Redirect- Response types - Middleware:
BodyLimitLayer,RequestIdLayer,TracingLayer- Request processing layers - Error Handling:
ApiError,Result- Structured error responses - Testing:
TestClient- Integration testing without network binding (requirestest-utilsfeature)
§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 middlewarecookies- Enable cookie parsing extractortest-utils- Enable testing utilities likeTestClientswagger-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
- Client
Ip - Client IP address extractor
- Created
- 201 Created response wrapper
- Extension
- Extension extractor
- Handler
Service - Wrapper to convert a Handler into a tower Service
- Header
Value - Single header value extractor
- Headers
- Headers extractor
- Html
- HTML response wrapper
- Json
- JSON body extractor
- Method
Router - 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
- Validated
Json - Validated JSON body extractor
- With
Status - Generic wrapper for returning a response with a custom status code.
Enums§
- Environment
- Environment configuration for error handling behavior
Traits§
- From
Request - Trait for extracting data from the full request (including body)
- From
Request Parts - Trait for extracting data from request parts (headers, path, query)
- Handler
- Trait representing an async handler function
- Into
Response - Trait for types that can be converted into an HTTP response
- Route
Handler - 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