-
-
Notifications
You must be signed in to change notification settings - Fork 37
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
add web Router service to rama-http #396
Comments
Hey! I came across this issue in This Week In Rust newsletter and I would love to have a crack at it if possible! |
All yours @nagxsan . Let me know if something is not clear, you want to discuss something or need help / have questions. Also feel free to open a PR if you want feedback or are stuck, have questions, etc. Thank you for your interest and take care! |
Thanks for assigning this task to me! I had a look at the two methods, using |
Sounds good. Do let me know if you need feedback, have questions or want to bounce some ideas around. Do also feel free to open a draft PR if you are stuck or require (early) feedback, all good. |
Hey @GlenDC , so this implementation would basically be a wrapper around |
Correct, you will have to write a separate service, which you can call the matchit's Matched params would then need to consumed as https://docs.rs/rama/latest/rama/http/matcher/struct.UriParams.html, using https://docs.rs/matchit/latest/matchit/struct.Params.html#method.iter, so that you can inject that |
You can see it like that, yes. The service would wrap https://docs.rs/matchit/latest/matchit/struct.Router.html and store services similar to |
I am going with a trie based approach with the following state that each trie node will hold:
I know this is slow and I am very sorry but I am kind of new to Rust so it is taking some time getting used to it. |
It's okay, also okay if you want to stop working on the issue as it might perhaps be a bit too much for where you are right now at your journey, no shame in that. That said, https://github.com/plabayo/rama/pull/423/files is not what was requested for this issue. The goal is really to make use of |
Hey, so sorry, I got a bit confused with the approaches. I have updated the code with the
In this, at this line:
Why is this happening? Also I will probably give it a try for a couple of more days and if I cannot make any further headway, it would probably be good if someone else picks it up. I am sorry for wasting your time as well. I felt that maybe a more hands-on task would help me practice my skills better. |
It's okay, it isn't an easy issue by any means, that's why I didn't add the label
Would need to see the entire error message to be sure, but you are doing some weird things there. For sure |
Issue available once again. @nagxsan thank you for the interest and enthusiasm though, greatly appreciated and respected. |
There's already a Matcher approach in https://docs.rs/rama/latest/rama/http/service/web/index.html, in two ways:
match_service!
macro: this is same-same but using tuples and thus no need to Box. It is however a bit less easy to use for first time usersBoth are very flexible in that they allow you to match on pretty much anything. However for a traditional web server it is a lot nicer to work with a trie-like structure to match purely on paths. You could still mix-and-match that with the two approaches above in case you want to specialise further (e.g. method) once you are in a path. This is possible as the two above still result in a
Service
(https://docs.rs/rama/latest/rama/trait.Service.html), which is also anEndpointService
(https://docs.rs/rama/latest/rama/http/service/web/trait.IntoEndpointService.html)The
Router
has to implement theService
trait (https://docs.rs/rama/latest/rama/trait.Service.html), which will be very similar to how https://docs.rs/rama/latest/rama/http/service/web/struct.WebService.html#impl-Service%3CState,+Request%3CBody%3E%3E-for-WebService%3CState%3E does it, except that you would do it using an approach focussed on paths. These paths should support extraction of segment data and wildcards out of the box and inject them similar to how a PatchMatcher (https://docs.rs/rama/latest/rama/http/matcher/struct.PathMatcher.html) does it.API interface could look like:
As part of implementing this
Router
you can addmatchit
as a dependency: https://docs.rs/matchit/latest/matchit/You could also go fancier and create also some kind of
RoutingService
which could wrap theWebService
and makes it a lot easier to chain based on common matchers such as methods etc, for same path. But that's more of an extra.Which would allow you to make it look more like:
Might be nicer and easier to implement, something to think about.
The text was updated successfully, but these errors were encountered: