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

Expose the matched route as an extension on the request #899

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

kyrias
Copy link
Contributor

@kyrias kyrias commented Sep 5, 2022

I considered adding it directly to the Request struct, though now I'm not sure anymore why I didn't, haha. I guess this PR is more of an RFC though. I would be happy with either implementation, but I do have a need for getting the route.


Edit: I remembered now why I chose not to add it to the Request struct which is that it feels cleaner to have the Request struct only deal with the actual client-submitted request, and the concept of a matched route is purely a server-side abstraction.

But since the Request already contains the list of captured route parameters I guess this point is a bit moot. Though I guess if this separation was wanted it wouldn't be unreasonable to remove the route_params struct member and turn that into an extension struct as well.

@Fishrock123
Copy link
Member

I think this is good, but it could just be a method on tide::Request IMO.

If the router found a matching route we store it as an extension struct
on the request and then expose it to the user as a method on `Request`.

Signed-off-by: Johannes Löthberg <johannes@kyriasis.com>
@kyrias
Copy link
Contributor Author

kyrias commented Sep 8, 2022

Reasonable. I've made the struct internal to the crate and added a method to get the extension now.

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.

2 participants