Skip to content

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

Merged
merged 1 commit into from
Apr 29, 2025
Merged

Conversation

itowlson
Copy link
Contributor

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.

@itowlson itowlson requested review from dicej and fibonacci1729 April 29, 2025 03:25
@itowlson
Copy link
Contributor Author

@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.

@itowlson itowlson force-pushed the route-on-trailing-wildcard branch from 0b3bfc1 to 67e175b Compare April 29, 2025 03:41
@@ -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
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor

@fibonacci1729 fibonacci1729 left a 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]>
@itowlson itowlson force-pushed the route-on-trailing-wildcard branch from 67e175b to 5bd986f Compare April 29, 2025 20:10
@itowlson itowlson merged commit 71c9aa4 into spinframework:main Apr 29, 2025
3 checks passed
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.

Support different routing modes
3 participants