pub struct Router { /* private fields */ }
Expand description
Exports HTTP Router items. The Spin SDK HTTP router.
Implementations§
source§impl Router
impl Router
sourcepub fn handle<R>(&self, request: R) -> Response
pub fn handle<R>(&self, request: R) -> Response
Synchronously dispatches a request to the appropriate handler along with the URI parameters.
sourcepub async fn handle_async<R>(&self, request: R) -> Response
pub async fn handle_async<R>(&self, request: R) -> Response
Asynchronously dispatches a request to the appropriate handler along with the URI parameters.
sourcepub 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,
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.
sourcepub 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,
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.
sourcepub 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,
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.
sourcepub 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,
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.
sourcepub 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,
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.
sourcepub 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,
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.
sourcepub 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,
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.
sourcepub 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,
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.
sourcepub 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,
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.
sourcepub 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,
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.
sourcepub 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,
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.
sourcepub 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,
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.
sourcepub 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,
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.
sourcepub 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,
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.
sourcepub 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,
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.
sourcepub 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,
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.
sourcepub 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,
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.
sourcepub 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,
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.