Skip to main content

Module web

Module web 

Source
Expand description

Web application framework (axum-like).

Built on top of Asupersync’s HTTP and Service layers, this module provides a high-level API for building web applications with type-safe routing, request extraction, and response conversion.

§Quick Start

use asupersync::web::{Router, Json, State, get, post};

async fn list_users(State(db): State<Db>) -> Json<Vec<User>> {
    Json(db.list_users().await)
}

async fn create_user(State(db): State<Db>, Json(input): Json<CreateUser>) -> StatusCode {
    db.insert(input).await;
    StatusCode::CREATED
}

let app = Router::new()
    .route("/users", get(list_users).post(create_user))
    .with_state(db);

§Extractors

Extractors pull data from incoming requests:

  • Path<T>: URL path parameters
  • Query<T>: Query string parameters
  • Json<T>: JSON request body
  • Cookie: Raw Cookie request header
  • CookieJar: Parsed request cookies
  • State<T>: Shared application state
  • HeaderMap: All request headers

§Responses

Any type implementing IntoResponse can be returned from handlers:

  • Json<T>: Serialize as JSON
  • Html<T>: HTML response
  • StatusCode: Status-only response
  • Redirect: HTTP redirect
  • Tuples of (StatusCode, impl IntoResponse) for custom status

Re-exports§

pub use extract::Cookie;
pub use extract::CookieJar;
pub use extract::Form;
pub use extract::FromRequest;
pub use extract::FromRequestParts;
pub use extract::Json as JsonExtract;
pub use extract::Path;
pub use extract::Query;
pub use extract::State;
pub use handler::AsyncCxFnHandler;
pub use handler::AsyncCxFnHandler1;
pub use handler::AsyncCxFnHandler2;
pub use handler::AsyncCxFnHandler3;
pub use handler::AsyncCxFnHandler4;
pub use handler::FnHandler;
pub use handler::FnHandler1;
pub use handler::FnHandler2;
pub use handler::FnHandler3;
pub use handler::FnHandler4;
pub use handler::Handler;
pub use nextjs_bootstrap::BootstrapCommand;
pub use nextjs_bootstrap::BootstrapLogEvent;
pub use nextjs_bootstrap::BootstrapRecoveryAction;
pub use nextjs_bootstrap::NextjsBootstrapConfig;
pub use nextjs_bootstrap::NextjsBootstrapError;
pub use nextjs_bootstrap::NextjsBootstrapSnapshot;
pub use nextjs_bootstrap::NextjsBootstrapState;
pub use response::Html;
pub use response::IntoResponse;
pub use response::Json;
pub use response::Redirect;
pub use response::Response;
pub use response::StatusCode;
pub use router::MethodRouter;
pub use router::Router;
pub use router::delete;
pub use router::get;
pub use router::patch;
pub use router::post;
pub use router::put;

Modules§

compress
Response compression middleware.
debug
Debug HTTP server for runtime inspection.
extract
Request extractors.
handler
Handler trait and implementations.
health
Health check endpoints for Kubernetes-style probes.
middleware
Combinator middleware for HTTP handlers.
multipart
Multipart form data parsing extractor.
negotiate
Content negotiation and error handler layer.
nextjs_bootstrap
Hydration-safe Next.js client bootstrap state machine.
request_region
Request-as-Region pattern for structured concurrency in HTTP handlers.
response
Response types and the IntoResponse trait.
router
HTTP router with method-based dispatch.
security
Security headers middleware.
session
Session middleware with pluggable storage backends.
sse
Server-Sent Events (SSE) support.
static_files
Static file serving with caching, ETag, and conditional request support.
websocket
WebSocket support for the web framework. WebSocket HTTP upgrade handler for the web framework.