Struct spin_sdk::http::Router

source ·
pub struct Router { /* private fields */ }
Expand description

Exports HTTP Router items. The Spin SDK HTTP router.

Implementations§

source§

impl Router

source

pub fn handle<R>(&self, request: R) -> Response

Synchronously dispatches a request to the appropriate handler along with the URI parameters.

source

pub async fn handle_async<R>(&self, request: R) -> Response

Asynchronously dispatches a request to the appropriate handler along with the URI parameters.

source

pub fn any<F, Req, Resp>(&mut self, path: &str, handler: F)
where F: Fn(Req, Params) -> Resp + 'static, Req: TryFromRequest + 'static, Req::Error: IntoResponse + 'static, Resp: IntoResponse + 'static,

Register a handler at the path for all methods.

source

pub fn any_async<F, Fut, I, O>(&mut self, path: &str, handler: F)
where F: Fn(I, Params) -> Fut + 'static, Fut: Future<Output = O> + 'static, I: TryFromRequest + 'static, I::Error: IntoResponse + 'static, O: IntoResponse + 'static,

Register an async handler at the path for all methods.

source

pub fn add<F, Req, Resp>(&mut self, path: &str, method: Method, handler: F)
where F: Fn(Req, Params) -> Resp + 'static, Req: TryFromRequest + 'static, Req::Error: IntoResponse + 'static, Resp: IntoResponse + 'static,

Register a handler at the path for the specified HTTP method.

source

pub fn add_async<F, Fut, I, O>( &mut self, path: &str, method: Method, handler: F )
where F: Fn(I, Params) -> Fut + 'static, Fut: Future<Output = O> + 'static, I: TryFromRequest + 'static, I::Error: IntoResponse + 'static, O: IntoResponse + 'static,

Register an async handler at the path for the specified HTTP method.

source

pub fn get<F, Req, Resp>(&mut self, path: &str, handler: F)
where F: Fn(Req, Params) -> Resp + 'static, Req: TryFromRequest + 'static, Req::Error: IntoResponse + 'static, Resp: IntoResponse + 'static,

Register a handler at the path for the HTTP GET method.

source

pub fn get_async<F, Fut, Req, Resp>(&mut self, path: &str, handler: F)
where F: Fn(Req, Params) -> Fut + 'static, Fut: Future<Output = Resp> + 'static, Req: TryFromRequest + 'static, Req::Error: IntoResponse + 'static, Resp: IntoResponse + 'static,

Register an async handler at the path for the HTTP GET method.

source

pub fn head<F, Req, Resp>(&mut self, path: &str, handler: F)
where F: Fn(Req, Params) -> Resp + 'static, Req: TryFromRequest + 'static, Req::Error: IntoResponse + 'static, Resp: IntoResponse + 'static,

Register a handler at the path for the HTTP HEAD method.

source

pub fn head_async<F, Fut, Req, Resp>(&mut self, path: &str, handler: F)
where F: Fn(Req, Params) -> Fut + 'static, Fut: Future<Output = Resp> + 'static, Req: TryFromRequest + 'static, Req::Error: IntoResponse + 'static, Resp: IntoResponse + 'static,

Register an async handler at the path for the HTTP HEAD method.

source

pub fn post<F, Req, Resp>(&mut self, path: &str, handler: F)
where F: Fn(Req, Params) -> Resp + 'static, Req: TryFromRequest + 'static, Req::Error: IntoResponse + 'static, Resp: IntoResponse + 'static,

Register a handler at the path for the HTTP POST method.

source

pub fn post_async<F, Fut, Req, Resp>(&mut self, path: &str, handler: F)
where F: Fn(Req, Params) -> Fut + 'static, Fut: Future<Output = Resp> + 'static, Req: TryFromRequest + 'static, Req::Error: IntoResponse + 'static, Resp: IntoResponse + 'static,

Register an async handler at the path for the HTTP POST method.

source

pub fn delete<F, Req, Resp>(&mut self, path: &str, handler: F)
where F: Fn(Req, Params) -> Resp + 'static, Req: TryFromRequest + 'static, Req::Error: IntoResponse + 'static, Resp: IntoResponse + 'static,

Register a handler at the path for the HTTP DELETE method.

source

pub fn delete_async<F, Fut, Req, Resp>(&mut self, path: &str, handler: F)
where F: Fn(Req, Params) -> Fut + 'static, Fut: Future<Output = Resp> + 'static, Req: TryFromRequest + 'static, Req::Error: IntoResponse + 'static, Resp: IntoResponse + 'static,

Register an async handler at the path for the HTTP DELETE method.

source

pub fn put<F, Req, Resp>(&mut self, path: &str, handler: F)
where F: Fn(Req, Params) -> Resp + 'static, Req: TryFromRequest + 'static, Req::Error: IntoResponse + 'static, Resp: IntoResponse + 'static,

Register a handler at the path for the HTTP PUT method.

source

pub fn put_async<F, Fut, Req, Resp>(&mut self, path: &str, handler: F)
where F: Fn(Req, Params) -> Fut + 'static, Fut: Future<Output = Resp> + 'static, Req: TryFromRequest + 'static, Req::Error: IntoResponse + 'static, Resp: IntoResponse + 'static,

Register an async handler at the path for the HTTP PUT method.

source

pub fn patch<F, Req, Resp>(&mut self, path: &str, handler: F)
where F: Fn(Req, Params) -> Resp + 'static, Req: TryFromRequest + 'static, Req::Error: IntoResponse + 'static, Resp: IntoResponse + 'static,

Register a handler at the path for the HTTP PATCH method.

source

pub fn patch_async<F, Fut, Req, Resp>(&mut self, path: &str, handler: F)
where F: Fn(Req, Params) -> Fut + 'static, Fut: Future<Output = Resp> + 'static, Req: TryFromRequest + 'static, Req::Error: IntoResponse + 'static, Resp: IntoResponse + 'static,

Register an async handler at the path for the HTTP PATCH method.

source

pub fn options<F, Req, Resp>(&mut self, path: &str, handler: F)
where F: Fn(Req, Params) -> Resp + 'static, Req: TryFromRequest + 'static, Req::Error: IntoResponse + 'static, Resp: IntoResponse + 'static,

Register a handler at the path for the HTTP OPTIONS method.

source

pub fn options_async<F, Fut, Req, Resp>(&mut self, path: &str, handler: F)
where F: Fn(Req, Params) -> Fut + 'static, Fut: Future<Output = Resp> + 'static, Req: TryFromRequest + 'static, Req::Error: IntoResponse + 'static, Resp: IntoResponse + 'static,

Register an async handler at the path for the HTTP OPTIONS method.

source

pub fn new() -> Self

Construct a new Router.

Trait Implementations§

source§

impl Default for Router

source§

fn default() -> Router

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

impl Display for Router

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl !RefUnwindSafe for Router

§

impl !Send for Router

§

impl !Sync for Router

§

impl Unpin for Router

§

impl !UnwindSafe for Router

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> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

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> ToString for T
where T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

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

§

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>,

§

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.