Skip to main content

ProductOSRouter

Enum ProductOSRouter 

Source
pub enum ProductOSRouter<S = ()> {
    Axum(AxumRouter<S>),
}
Expand description

Main router enum for Product OS Router

Dispatches to either Axum or Flow implementation based on feature flags. Provides a high-level API for defining routes, handlers, and middleware. Supports both stateful and stateless routing.

§Type Parameters

  • S - The state type (defaults to () for stateless routing)

§Examples

§Stateless Router

use product_os_router::ProductOSRouter;

async fn handler() -> &'static str {
    "Hello!"
}

let mut router = ProductOSRouter::new();
router.add_get_no_state("/", handler);

§Stateful Router

use product_os_router::{ProductOSRouter, State};

#[derive(Clone)]
struct AppState {
    message: String,
}

async fn handler(State(state): State<AppState>) -> String {
    state.message
}

let state = AppState { message: "Hello!".to_string() };
let mut router = ProductOSRouter::new_with_state(state);
router.add_get("/", handler);

Variants§

§

Axum(AxumRouter<S>)

Implementations§

Source§

impl<S> ProductOSRouter<S>
where S: Clone + Send + Sync + 'static,

Source

pub fn new_with_state(state: S) -> ProductOSRouter<S>

Create a new router with the given shared state.

Source§

impl ProductOSRouter

Source

pub fn new() -> ProductOSRouter

Create a new stateless router

Creates a router without any shared state. Use new_with_state if you need to share state between handlers.

§Examples
use product_os_router::ProductOSRouter;

let router = ProductOSRouter::new();
Source§

impl ProductOSRouter

Source

pub fn param_to_field(path: &str) -> String

Convert path parameters from Express-style to Axum format

Source

pub fn not_implemented() -> Response<Body>

Returns a 501 Not Implemented JSON response

Source

pub fn not_implemented_legacy() -> Response<Body>

👎Deprecated since 0.0.41:

Use not_implemented() which correctly returns 501, or build a 404 response explicitly

Returns a 404 Not Found JSON response

Source

pub fn add_get_no_state<H, T>(&mut self, path: &str, handler: H)
where H: Handler<T, ()> + Send + Sync + 'static, T: 'static,

Add a GET route handler without state

Source

pub fn add_post_no_state<H, T>(&mut self, path: &str, handler: H)
where H: Handler<T, ()> + Send + Sync + 'static, T: 'static,

Add a POST route handler without state

Source

pub fn add_handler_no_state<H, T>( &mut self, path: &str, method: Method, handler: H, )
where H: Handler<T, ()> + Send + Sync + 'static, T: 'static,

Add a handler for the given HTTP method without state

Source

pub fn add_default_header_no_state( &mut self, header_name: &str, header_value: &str, )

Add a default header without state

Source

pub fn set_fallback_handler_no_state<H, T>(&mut self, handler: H)
where H: Handler<T, ()> + Send + Sync + 'static, T: 'static,

Set a fallback handler without state

Source

pub fn add_handlers_no_state<H, T>( &mut self, path: &str, handlers: BTreeMap<Method, H>, )
where H: Handler<T, ()> + Send + Sync + 'static, T: 'static,

Add multiple handlers without state

Source§

impl<S> ProductOSRouter<S>
where S: Clone + Send + Sync + 'static,

Source

pub fn get_router(&self) -> ProductOSRouter<S>

Return a clone of the router.

For both Axum and Flow, returns ProductOSRouter<S>. Use into_axum_router() when you need the raw axum::Router.

Source

pub fn into_axum_router(self) -> Router

Extract the inner axum::Router, consuming the wrapper.

This is needed when handing the router to axum-specific server functions that expect a raw axum::Router.

Source

pub fn add_get<H, T>(&mut self, path: &str, handler: H)
where H: Handler<T, S> + Send + Sync + 'static, T: 'static,

Add a GET route handler

Source

pub fn add_post<H, T>(&mut self, path: &str, handler: H)
where H: Handler<T, S> + Send + Sync + 'static, T: 'static,

Add a POST route handler

Source

pub fn add_handler<H, T>(&mut self, path: &str, method: Method, handler: H)
where H: Handler<T, S> + Send + Sync + 'static, T: 'static,

Add a handler for the given HTTP method and path

Source

pub fn add_default_header(&mut self, header_name: &str, header_value: &str)

Add a default header

Source

pub fn add_handlers<H, T>(&mut self, path: &str, handlers: BTreeMap<Method, H>)
where H: Handler<T, S> + Send + Sync + 'static, T: 'static,

Add multiple HTTP method handlers at a single path

Source

pub fn add_route(&mut self, path: &str, method_router: MethodRouter<S>)
where S: Clone + Send + Sync + 'static,

Add a route with an Axum MethodRouter.

Source

pub fn set_fallback(&mut self, service_handler: MethodRouter<S>)
where S: Clone + Send + Sync + 'static,

Set the fallback service for unmatched routes (Axum MethodRouter).

Source

pub fn set_fallback_handler<H, T>(&mut self, handler: H)
where H: Handler<T, S>, T: 'static,

Set the fallback handler for unmatched routes.

Source

pub fn add_middleware<L, ResBody>(&mut self, middleware: L)
where L: Layer<Route> + Clone + Send + Sync + 'static, <L as Layer<Route>>::Service: Service<Request<Body>, Response = Response<ResBody>> + Clone + Send + Sync + 'static, <<L as Layer<Route>>::Service as Service<Request<Body>>>::Future: Send, <<L as Layer<Route>>::Service as Service<Request<Body>>>::Error: Into<Box<dyn Error + Send + Sync>>, ResBody: Body<Data = Bytes> + Send + 'static, <ResBody as Body>::Error: Into<Box<dyn Error + Send + Sync>>,

Add an Axum-compatible Tower middleware layer.

Source§

impl<S> ProductOSRouter<S>
where S: Clone + Send + Sync + 'static,

Source

pub fn add_extension<T>(&mut self, value: T)
where T: Clone + Send + Sync + 'static,

Inserts a value into request extensions for all subsequent handlers.

Trait Implementations§

Source§

impl<S> Clone for ProductOSRouter<S>
where S: Clone + Send + Sync + 'static,

Available on crate feature framework_axum only.
Source§

fn clone(&self) -> ProductOSRouter<S>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Default for ProductOSRouter

Available on crate features framework_axum or framework_flow only.
Source§

fn default() -> ProductOSRouter

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<S = ()> !RefUnwindSafe for ProductOSRouter<S>

§

impl<S = ()> !UnwindSafe for ProductOSRouter<S>

§

impl<S> Freeze for ProductOSRouter<S>
where S: Freeze,

§

impl<S> Send for ProductOSRouter<S>
where S: Send,

§

impl<S> Sync for ProductOSRouter<S>
where S: Sync,

§

impl<S> Unpin for ProductOSRouter<S>
where S: Unpin,

§

impl<S> UnsafeUnpin for ProductOSRouter<S>
where S: UnsafeUnpin,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FromRef<T> for T
where T: Clone,

Source§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more