Expand description
§Product OS Router
A fully-featured HTTP router built on top of Axum and Tower, providing convenient helper methods for creating HTTP, HTTPS, WebSocket, and Server-Sent Events (SSE) servers.
§Features
- Easy Routing: Simple, chainable API for defining routes
- HTTP Methods: Support for GET, POST, PUT, PATCH, DELETE, and more
- State Management: Both stateful and stateless routing options
- WebSockets: Built-in WebSocket support (with
wsfeature) - Server-Sent Events: SSE support (with
ssefeature) - CORS: Cross-Origin Resource Sharing support (with
corsfeature) - Middleware: Custom middleware support (with
middlewarefeature) - Default Headers: Apply default headers to all responses
- Protocol Upgrade: HTTP to HTTPS automatic redirection
- Path Parameters: Express-style path parameter syntax (
:param,*wildcard) - no_std Support: Can be used in no_std environments with alloc
§Quick Start
use product_os_router::{ProductOSRouter, IntoResponse};
async fn hello_world() -> &'static str {
"Hello, World!"
}
let mut router = ProductOSRouter::new();
router.add_get_no_state("/", hello_world);
let app = router.get_router();
// Use app with your server (e.g., axum::Server)§Path Parameter Syntax
The router automatically converts Express-style path parameters to Axum format:
:parambecomes{param}(single segment)*wildcardbecomes{wildcard}(catch-all)
async fn user_handler(Path(id): Path<u32>) -> String {
format!("User ID: {}", id)
}
let mut router = ProductOSRouter::new();
router.add_get_no_state("/users/:id", user_handler); // Converted to /users/{id}§With State
#[derive(Clone)]
struct AppState {
counter: u32,
}
async fn handler(State(state): State<AppState>) -> String {
format!("Counter: {}", state.counter)
}
let state = AppState { counter: 0 };
let mut router = ProductOSRouter::new_with_state(state);
router.add_get("/", handler);§Feature Flags
default: Includesframework_axumandstdfeaturesframework_axum: Axum framework (existing, stable)framework_flow: Flow framework (new, high-performance)std: Standard library supportcore: Core routing functionalityws: WebSocket supportsse: Server-Sent Events supportcors: CORS middleware supportsessions: Session management supportmiddleware: Custom middleware traitsdebug: Debug handler macros
Re-exports§
pub use crate::dual_protocol::UpgradeHttpLayer;pub use crate::dual_protocol::Protocol;
Modules§
- dual_
protocol - HTTP to HTTPS upgrade layer
Structs§
- AsService
- Service returned by
MakeService::as_service. - Body
- The body type used in axum requests and responses.
- Body
Bytes - Concrete implementation of (Body).
- Bytes
- A cheaply cloneable and sliceable chunk of contiguous memory.
- Connect
Info - Extractor for getting connection information produced by a
Connected. - Default
Headers Layer - Layer for adding default HTTP response headers
- Extension
- Extractor that gets a value from request extensions.
- Form
- URL encoded extractor and response.
- Header
Map - A specialized multimap for header names and values.
- Header
Name - Represents an HTTP header field name
- Header
Value - Represents an HTTP header field value.
- Into
Service - Service returned by
MakeService::into_service. - Json
- JSON Extractor / Response.
- Method
Router - A
Servicethat accepts requests based on aMethodFilterand allows chaining additional handlers and services. - Next
- The remainder of a middleware stack, including the handler.
- Path
- Extractor that will get captures from the URL and parse them using
serde. - Query
- Extractor that deserializes query strings into some type.
- Redirect
- Response that redirects the request to another location.
- Request
- Represents an HTTP request.
- Request
Id - Request ID extractor.
- Request
Method - Extractor for HTTP request method
- Request
Parts - Component parts of an HTTP
Request - Response
- Represents an HTTP response
- Response
Parts - Component parts of an HTTP
Response - Router
- The router type for composing handlers and services.
- Scheme
- Represents the scheme component of a URI
- Service
Builder - Declaratively construct
Servicevalues. - Service
Fn - A
Serviceimplemented by a closure. - Shared
- A
MakeServicethat produces services by cloning an inner service. - Shared
Future - Response future from
Sharedservices. - State
- Extractor for state.
- Status
Code - An HTTP status code (
status-codein RFC 9110 et al.). - Trace
Context - Parsed W3C
traceparentheader. - Uri
- The URI component of a request.
- WebSocket
- A stream of WebSocket messages.
- WebSocket
Upgrade - Extractor for establishing WebSocket connections.
Enums§
- Message
- A WebSocket message.
- Method
- HTTP request method enumeration
- ProductOS
Router - Main router enum for Product OS Router
- ProductOS
Router Error
Traits§
- FromRef
- Used to do reference-to-value conversions thus not consuming the input value.
- From
Request - Types that can be created from requests.
- From
Request Parts - Types that can be created from request parts.
- Handler
- Trait for async functions that can be used to handle requests.
- Http
Body - Trait representing a streaming body of a Request or Response.
- Into
Response - Trait for generating responses.
- Layer
- Decorates a
Service, transforming either the request or the response. - Make
Connection - The
MakeConnectiontrait is used to create transports. - Make
Service - Creates new
Servicevalues. - Service
- An asynchronous function from a
Requestto aResponse. - Service
Ext - An extension trait for
Services that provides a variety of convenient adapters
Functions§
- any
- Route requests with the given handler regardless of the method.
- delete
- Route
DELETErequests to the given handler. - extension_
layer - from_fn
- Create a middleware from an async function.
- from_
fn_ with_ state - Create a middleware from an async function with the given state.
- get
- Route
GETrequests to the given handler. - head
- Route
HEADrequests to the given handler. - options
- Route
OPTIONSrequests to the given handler. - patch
- Route
PATCHrequests to the given handler. - post
- Route
POSTrequests to the given handler. - put
- Route
PUTrequests to the given handler. - service_
fn - Returns a new
ServiceFnwith the given closure. - trace
- Route
TRACErequests to the given handler.
Type Aliases§
- BoxError
- Alias for a type-erased error type.