Skip to main content

Crate toxi

Crate toxi 

Source
Expand description

§Toxi Web Framework

Toxi is a modular, batteries-included web framework for Rust. Built on hyper and tokio, it provides a complete stack for building production HTTP services — routing, ORM, authentication, real-time communication, background jobs, caching, storage, templates, email, and OpenAPI generation.

§Quick Start

[dependencies]
toxi = { version = "3.1.0", features = ["full"] }
tokio = { version = "1", features = ["full"] }
serde = { version = "1", features = ["derive"] }
use toxi::prelude::*;

async fn hello(_req: Request) -> Result<Response> {
    Ok(Response::text("Hello, Toxi!"))
}

#[tokio::main]
async fn main() -> Result<()> {
    let mut app = Application::new(Config::load().unwrap());
    app.router_mut().get("/", hello);
    app.run().await
}

§Feature Flags

Enable only what you need via Cargo features:

FeatureCrateDescription
databasetoxi-dbORM with relationships & migrations
authtoxi-authJWT, OAuth2, RBAC, 2FA, API keys
queuetoxi-queueBackground job orchestration
cachetoxi-cacheIn-memory and Redis caching
realtimetoxi-realtimeWebSocket and SSE
templatestoxi-templateServer-side rendering
mailtoxi-mailSMTP email delivery
storagetoxi-storageLocal and S3 file storage
securitytoxi-securityCrypto primitives
utilstoxi-utilsString, date, validation helpers
graphqltoxi-graphqlGraphQL integration
plugintoxi-pluginPlugin lifecycle hooks
fullall of the aboveEvery optional crate

§Modular by Design

Each crate in the Toxi ecosystem can be used independently:

# Minimal: just routing and HTTP
[dependencies]
toxi-core = "3.1.0"

# Add database when needed
[dependencies]
toxi-core = "3.1.0"
toxi-db = "3.1.0"

§Key Concepts

  • Extractors — Typed data pulled from requests (Json<T>, Path<T>, State<T>, etc.)
  • Handlers — Async functions whose parameters are extractors
  • Middleware — Tower-compatible layers (CORS, logging, compression, rate limiting)
  • HTTP/2 — First-class support via ALPN or Server::with_http_version

§Learn More

Re-exports§

pub use config_helper::cors_layer_from_config;
pub use toxi_middleware as middleware;
pub use toxi_config as config;
pub use toxi_db as db;
pub use toxi_auth as auth;
pub use toxi_queue as queue;
pub use toxi_cache as cache;
pub use toxi_realtime as realtime;
pub use toxi_template as template;
pub use toxi_mail as mail;
pub use toxi_storage as storage;
pub use toxi_security as security;
pub use toxi_utils as utils;

Modules§

app
Re-export all items from toxi_core. Application boot coordinator and configuration.
config_helper
Configuration helper utilities.
cookie
Re-export all items from toxi_core. Backwards-compatible re-exports for cookies and form data. Backwards-compatible cookie/form module.
error
Re-export all items from toxi_core. Error types and the Result alias.
extract
Re-export the extract module from toxi_core. Request extractors for pulling typed data from incoming requests.
mpsc
Re-export all items from toxi_core. Re-export of tokio::sync::mpsc for channel-based communication. A multi-producer, single-consumer queue for sending values between asynchronous tasks.
prelude
Convenience re-exports for ergonomic imports.
request
Re-export all items from toxi_core. Extension trait for Request with body-reading helpers.
response
Re-export all items from toxi_core. Response constructors and helpers.
router
Re-export all items from toxi_core. HTTP router with path parameters, middleware, and CORS support.
server
Re-export all items from toxi_core. HTTP/1.1 and HTTP/2 server loop and body adapter.
tls
Re-export all items from toxi_core. TLS/HTTPS support and SecureServer.
types
Re-export all items from toxi_core. Type aliases for requests, responses, and boxed bodies.
versioning
Re-export all items from toxi_core. API versioning with ApiVersion and VersionedRouter. API Versioning support

Macros§

impl_handler_for_fn
Re-export impl_handler_for_fn! — extend handler arity beyond the built-in 12 extractors:
json_response
Re-export json_response! — create a JSON response from inline JSON:

Structs§

Application
Re-export all items from toxi_core. The application boot coordinator. Application boot coordinator.
Body
Re-export all items from toxi_core. Common request extractors. Extract raw request body as string
Cookies
Re-export all items from toxi_core. Common request extractors. Extract cookies from the request
CorsConfig
Re-export all items from toxi_core. Router and handler types. CORS configuration for the Router
Form
Re-export all items from toxi_core. Common request extractors. Extract form data from the request body
HeaderMap
Re-export all items from toxi_core. Re-exports from the http crate. A specialized multimap for header names and values.
HeaderValue
Re-export all items from toxi_core. Re-exports from the http crate. Represents an HTTP header field value.
Json
Re-export all items from toxi_core. Common request extractors. Extract and deserialize JSON request body
Method
Re-export all items from toxi_core. Re-exports from the http crate. The Request Method (VERB)
Path
Re-export all items from toxi_core. Common request extractors. Extract typed path parameters from the request
PathParams
Re-export all items from toxi_core. Common request extractors. Storage for path parameters extracted during routing.
Query
Re-export all items from toxi_core. Common request extractors. Extract typed query parameters from the request
Response
Re-export all items from toxi_core. Convenience alias: ToxiResponse as Response. The Toxi HTTP response type.
Router
Re-export all items from toxi_core. Router and handler types. The central request router.
Server
Re-export all items from toxi_core. The HTTP server. HTTP server that listens for incoming connections and dispatches requests to a tower service.
State
Re-export all items from toxi_core. Common request extractors. Extract application state from request extensions
StatusCode
Re-export all items from toxi_core. Re-exports from the http crate. An HTTP status code (status-code in RFC 9110 et al.).
ToxiResponse
Re-export ToxiRequest and ToxiResponse. The Toxi HTTP response type.
VersionedRouter
Re-export all items from toxi_core. API versioning types. Versioned router
WebSocketUpgrade
Re-export all items from toxi_core. Common request extractors. Extractor for WebSocket upgrade requests

Enums§

ApiVersion
Re-export all items from toxi_core. API versioning types. API version
Error
Re-export all items from toxi_core. Core error and result types. Error type for Toxi applications.
HttpVersion
Re-export all items from toxi_core. The HTTP server. HTTP protocol version for the server.

Traits§

BodyExt
Re-export all items from toxi_core. Re-export of http_body_util::BodyExt for body-reading utilities. An extension trait for http_body::Body adding various combinators and adapters
FromRequest
Re-export all items from toxi_core. Common request extractors. Extractor trait - allows types to be extracted from requests.
Handler
Re-export all items from toxi_core. Router and handler types. Trait for async functions that can be used as handlers
IntoHandler
Re-export all items from toxi_core. Router and handler types. Trait that provides compile-time verification that a function is a valid handler.

Functions§

handler_fn
Re-export all items from toxi_core. Router and handler types. Compile-time handler verification helper.
html
Re-export all items from toxi_core. Re-export response helpers for convenient access.
json
Re-export all items from toxi_core. Re-export response helpers for convenient access.
text
Re-export all items from toxi_core. Re-export response helpers for convenient access.

Type Aliases§

Request
Re-export all items from toxi_core. Convenience alias: ToxiRequest as Request. The Toxi HTTP request type.
Result
Re-export all items from toxi_core. Core error and result types. A specialized Result type for Toxi applications
ToxiRequest
Re-export ToxiRequest and ToxiResponse. The Toxi HTTP request type.