Skip to main content

Crate product_os_router

Crate product_os_router 

Source
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 ws feature)
  • Server-Sent Events: SSE support (with sse feature)
  • CORS: Cross-Origin Resource Sharing support (with cors feature)
  • Middleware: Custom middleware support (with middleware feature)
  • 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:

  • :param becomes {param} (single segment)
  • *wildcard becomes {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: Includes framework_axum and std features
  • framework_axum: Axum framework (existing, stable)
  • framework_flow: Flow framework (new, high-performance)
  • std: Standard library support
  • core: Core routing functionality
  • ws: WebSocket support
  • sse: Server-Sent Events support
  • cors: CORS middleware support
  • sessions: Session management support
  • middleware: Custom middleware traits
  • debug: 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.
BodyBytes
Concrete implementation of (Body).
Bytes
A cheaply cloneable and sliceable chunk of contiguous memory.
ConnectInfo
Extractor for getting connection information produced by a Connected.
DefaultHeadersLayer
Layer for adding default HTTP response headers
Extension
Extractor that gets a value from request extensions.
Form
URL encoded extractor and response.
HeaderMap
A specialized multimap for header names and values.
HeaderName
Represents an HTTP header field name
HeaderValue
Represents an HTTP header field value.
IntoService
Service returned by MakeService::into_service.
Json
JSON Extractor / Response.
MethodRouter
A Service that accepts requests based on a MethodFilter and 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.
RequestId
Request ID extractor.
RequestMethod
Extractor for HTTP request method
RequestParts
Component parts of an HTTP Request
Response
Represents an HTTP response
ResponseParts
Component parts of an HTTP Response
Router
The router type for composing handlers and services.
Scheme
Represents the scheme component of a URI
ServiceBuilder
Declaratively construct Service values.
ServiceFn
A Service implemented by a closure.
Shared
A MakeService that produces services by cloning an inner service.
SharedFuture
Response future from Shared services.
State
Extractor for state.
StatusCode
An HTTP status code (status-code in RFC 9110 et al.).
TraceContext
Parsed W3C traceparent header.
Uri
The URI component of a request.
WebSocket
A stream of WebSocket messages.
WebSocketUpgrade
Extractor for establishing WebSocket connections.

Enums§

Message
A WebSocket message.
Method
HTTP request method enumeration
ProductOSRouter
Main router enum for Product OS Router
ProductOSRouterError

Traits§

FromRef
Used to do reference-to-value conversions thus not consuming the input value.
FromRequest
Types that can be created from requests.
FromRequestParts
Types that can be created from request parts.
Handler
Trait for async functions that can be used to handle requests.
HttpBody
Trait representing a streaming body of a Request or Response.
IntoResponse
Trait for generating responses.
Layer
Decorates a Service, transforming either the request or the response.
MakeConnection
The MakeConnection trait is used to create transports.
MakeService
Creates new Service values.
Service
An asynchronous function from a Request to a Response.
ServiceExt
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 DELETE requests 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 GET requests to the given handler.
head
Route HEAD requests to the given handler.
options
Route OPTIONS requests to the given handler.
patch
Route PATCH requests to the given handler.
post
Route POST requests to the given handler.
put
Route PUT requests to the given handler.
service_fn
Returns a new ServiceFn with the given closure.
trace
Route TRACE requests to the given handler.

Type Aliases§

BoxError
Alias for a type-erased error type.