Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rama web router #423

Closed
wants to merge 2 commits into from
Closed

Rama web router #423

wants to merge 2 commits into from

Conversation

nagxsan
Copy link

@nagxsan nagxsan commented Feb 16, 2025

Fixes #396

@nagxsan nagxsan marked this pull request as draft February 16, 2025 12:14
Copy link
Member

@GlenDC GlenDC left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please make use of matchit and adapt the code accordingly.

let uri_string = req.uri().to_string();
match &self.routes.at(uri_string.as_str()) {
Ok(matched) => {
let params: HashMap<String, String> = matched.params.clone().iter().map(|(k, v)| (k.to_string(), v.to_string())).collect();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will need to be collected as https://docs.rs/rama/latest/rama/http/matcher/struct.UriParams.html to be compatible with the existing matcher object. Feel free to expand the logic of UriParams if you miss something.

E.g. might make code cleaner here if you implement FromIterator for UriParams, but that's more of an optional thing.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also in general there should be no reason to double allocate.

  1. first allocation is .clone()
  2. than you allocate again by turning the pairs into owned pairs

Probably that first clone isn't needed

@@ -100,7 +49,125 @@ where
/// create a new web router
pub(crate) fn new() -> Self {
Self {
routes: TrieNode::new(),
routes: MatchitRouter::new(),
not_found: Arc::new(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this can probably be made optional so you don't need to assign it if not set, and instead just fallback to NOT_FOUND anyway but on the spot

pub struct Router<State> {
routes: TrieNode<State>
routes: MatchitRouter<HashMap<Method, Arc<BoxService<State, Request, Response, Infallible>>>>,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We also need to be able to nest and merge btw, so I think this approach is a bit too simplistic

@GlenDC
Copy link
Member

GlenDC commented Feb 17, 2025

Closed as this isn't the desired approach and won't be continued as communicated off channel.

@GlenDC GlenDC closed this Feb 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

add web Router service to rama-http
2 participants