Comments (9)
This sums it up! Thanks for the clarification, and thank you for this great framework!
from xitca-web.
Thanks for the issue. This is a limitation and bug in the router where it will lose context of router path generating once it's nested. I would look into it.
from xitca-web.
With #957 this issue is resolved.
from xitca-web.
That said do note that xitca routing nested router in linear manner. which means for the example use in this issue there will be three routers generated:
/api/*
/api/v2/*
/api/v2/create
A request path must be matched against every one in top down order to find the according route service. Apparently this is less efficient than using single router.
This is for simple router design by keeping it consistent with matchit
. If more efficient nesting routers is desired I would suggest opening issue to said crate for a native support. I'm also open to idea of using other router crates that can achieve the same goal.
from xitca-web.
Do you mean that you have to do 3 match_it.at
calls to reach it?
from xitca-web.
Do you mean that you have to do 3
match_it.at
calls to reach it?
yes that's correct. I would close this issue for now as functionally the multiple nesting has been resolved.
from xitca-web.
@fakeshadow any reason on why not make it simple by collecting added routes and adding it directly to the main matchit
router? I was playing with making a http framework on top of hyper and had these two functions that collect all routes to main router, here is what I mean:
#[inline]
pub fn generate(self) -> Result<MatchRouter<F>, matchit::InsertError> {
let mut match_router = MatchRouter::new();
let handlers: Vec<(Option<Method>, Handler<F>)> = self.handlers;
match_router.insert(&self.path, handlers)?;
Self::child_routers(self.routers, &mut match_router)?;
Ok(match_router)
}
#[inline]
fn child_routers(
routers: Vec<Router<F>>,
match_router: &mut MatchRouter<F>,
) -> Result<(), matchit::InsertError> {
for router in routers {
let handlers: Vec<(Option<Method>, Handler<F>)> = router.handlers;
match_router.insert(router.path, boxed_router)?;
Self::child_routers(router.routers, match_router)?;
}
Ok(())
}
I believe this significantly simplifies the process and aligns with the intended use of matchit.
from xitca-web.
Because xitca is a composable framework where a route can be one of many possible types. For example:
App::new()
.at("/1", fn_service(..))
.at("/2", get(fn_service(..)))
.at("/3", Redirect::see_other("/1"))
.at("/4", Router::new())
.at("/5", Router::new().ecnlosed(Middleware))
Everyone of them would produce different types of route and the only way to store them in a single router is to cast them into trait objects where the types are erased so there is no way to know what route is a nest router.
It's possible to add new trait bound for additional logic to handle routes differently based on their types which is what xitca is already doing where PathGen
and RouteGen
traits are used. That being said this approach also coming with one down side.
below is a router with middleware:
let mut router = Router::new().ecnlosed(Middleware));
In order to transform it to a router you have to do this:
router = router.drain().map(|(k, v)| (k, v.enclosed(Middleware)).collect();
Which means you have to construct a separate middleware for every route in the router instead of only construct one around the router itself. This can result in exponential memory bloating when multiple routes are stored in a router with multiple middlewares around the router. And one of the most important design choice of xitca is to be memory efficient when possible which means we always choose some extra cpu cycle compared to more allocated memory.
from xitca-web.
A new release has been made to address the issue. And the release has also "fixed" the performance issue of multi layer of nesting.
With the new release multi layer of nesting routers will only pay for extra request path string slicing(to avoid repeatedly walk the whole string for matching route) and boxed object of indirection pointer look up.
from xitca-web.
Related Issues (20)
- i saw the techempower benchmark, is it really thread per core? HOT 3
- new to xitca web, how to compile this? HOT 1
- it's nice but http/2 or http3 :443 has issues HOT 12
- possible to do a http2 websocket example? current one is only http1.1 HOT 2
- too many file descriptors. possible to do one that share 1 file descriptor? (feature request) HOT 7
- is it easy to show an example of using websocket with http2 and http3 together? HOT 9
- can you show an example of Router /hello hello world text for xitca multi http2/3? HOT 1
- how to get remote ip address HOT 1
- how to drop a connection as fast as possible? (in the event of ddos attack) HOT 5
- how to have websocket, http2/3, router on the same script? HOT 5
- Chatgpt multiple errors unexpected! HOT 1
- rustls-ring-crypto for server HOT 4
- http client request HOT 2
- [Question] How store `FnService<F>`? HOT 1
- [求助]websocket怎么在任意上下文使用呢? HOT 2
- Named Parameters HOT 1
- how to do so reuseport? HOT 1
- problem encountered for cargo run. how to debug? HOT 1
- spawning xitca_server address in use error HOT 7
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from xitca-web.