Skip to content

Commit

Permalink
feat(volo-http): support any for routing any methods (#298)
Browse files Browse the repository at this point in the history
* feat(volo-http): add `any` for routing any methods
* chore(volo-http): re-export `Router`, `Query` and `Form`

---------

Signed-off-by: Yu Li <[email protected]>
  • Loading branch information
yukiiiteru authored Dec 26, 2023
1 parent 7b6bab2 commit 4208ccd
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
3 changes: 2 additions & 1 deletion volo-http/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,11 @@ pub use volo::net::Address;

pub use crate::{
context::{ConnectionInfo, HttpContext},
extract::{Json, MaybeInvalid, State},
extract::{Form, Json, MaybeInvalid, Query, State},
param::Params,
request::Request,
response::Response,
route::Router,
server::Server,
};

Expand Down
18 changes: 18 additions & 0 deletions volo-http/src/route.rs
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,15 @@ where

for_all_methods!(impl_method_register_for_builder);

pub fn fallback<H, T>(mut self, handler: H) -> Self
where
for<'a> H: Handler<T, S> + Clone + Send + Sync + 'a,
for<'a> T: 'a,
{
self.router.fallback = Fallback::Handler(DynHandler::new(handler));
self
}

pub fn build(self) -> MethodRouter<S> {
self.router
}
Expand All @@ -419,6 +428,15 @@ macro_rules! impl_method_register {

for_all_methods!(impl_method_register);

pub fn any<H, T, S>(h: H) -> MethodRouter<S>
where
for<'a> H: Handler<T, S> + Clone + Send + Sync + 'a,
for<'a> T: 'a,
S: Clone + Send + Sync + 'static,
{
MethodRouterBuilder::new().fallback(h).build()
}

#[derive(Clone, Default)]
pub enum MethodEndpoint<S> {
#[default]
Expand Down

0 comments on commit 4208ccd

Please sign in to comment.