@@ -591,7 +591,32 @@ fn trailing_suffix(req: &Request) -> Option<&str> {
591591 . and_then ( |path_info| path_info. as_str ( ) )
592592}
593593
594- /// A macro to help with constructing a Router from a stream of tokens.
594+ /// A macro to help with constructing a [`Router`] from method-pattern-handler triples.
595+ ///
596+ /// # Examples
597+ ///
598+ /// ```no_run
599+ /// # use spin_sdk::http_router;
600+ /// # use spin_sdk::http::{IntoResponse, Params, Request, Response, Router};
601+ /// fn handle_route(req: Request) -> Response {
602+ /// let router = http_router! {
603+ /// GET "/user" => list_users,
604+ /// POST "/user" => create_user,
605+ /// GET "/user/:id" => get_user,
606+ /// PUT "/user/:id" => update_user,
607+ /// DELETE "/user/:id" => delete_user,
608+ /// _ "/user" => method_not_allowed,
609+ /// _ "/user/:id" => method_not_allowed
610+ /// };
611+ /// router.handle(req)
612+ /// }
613+ /// # fn list_users(req: Request, params: Params) -> anyhow::Result<Response> { todo!() }
614+ /// # fn create_user(req: Request, params: Params) -> anyhow::Result<Response> { todo!() }
615+ /// # fn get_user(req: Request, params: Params) -> anyhow::Result<Response> { todo!() }
616+ /// # fn update_user(req: Request, params: Params) -> anyhow::Result<Response> { todo!() }
617+ /// # fn delete_user(req: Request, params: Params) -> anyhow::Result<Response> { todo!() }
618+ /// # fn method_not_allowed(req: Request, params: Params) -> anyhow::Result<Response> { todo!() }
619+ /// ```
595620#[ macro_export]
596621macro_rules! http_router {
597622 ( $( $method: tt $path: literal => $h: expr) ,* ) => {
0 commit comments