-
Notifications
You must be signed in to change notification settings - Fork 13
Routing modes #66
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
Routing modes #66
Conversation
@fibonacci1729 I went for now with your constructor idea from #51. It would be easy to change it to make the decision at handle time instead of construction time if you're leaning that way. |
0b3bfc1
to
67e175b
Compare
@@ -154,9 +154,38 @@ pub type Params = Captures<'static, 'static>; | |||
/// # fn handle_single_segment(req: Request, params: Params) -> anyhow::Result<Response> { todo!() } | |||
/// # fn handle_exact(req: Request, params: Params) -> anyhow::Result<Response> { todo!() } | |||
/// ``` | |||
/// | |||
/// Route based on the trailing segment of a Spin wildcard route, instead of on the full path |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know this follows an existing pattern, but it somehow feels weird that the example code here is on the struct itself instead of on the method. But maybe I would feel the same way if it were the other way around?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rylev Good point. My rough thinking is that these don't document handle()
or suffix()
in isolation, but rather the interaction between new()/suffix()
, get/post/put/etc
, and handle()
- that is, they are examples of "how to use the Router struct", rather than an individual method in isolation. It does lead to a rather large and hard to navigate docs block though.
And there's something to be said for also having examples on individual methods, because a reader might have an anchored link that takes them directly to a method and bypasses the struct docs.
For now, I'm going to punt on this for this PR, and we can re-assess and/or try different things as part of a separate examples pass.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks great @itowlson ! Thanks for knocking it out. I can work on getting a release out once we land this.
Signed-off-by: itowlson <[email protected]>
67e175b
to
5bd986f
Compare
Fixes #51
The unit test is rather synthetic because it relies on the same assumption that the functional code uses, but I couldn't think of a way to force a request through Real Actual Spin. I did test with an actual Spin binary and it behaved as desired. Better ideas welcome.