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

Allow passing around req/resp http::Extensions #21

Merged
merged 4 commits into from
Mar 28, 2024
Merged

Conversation

tclem
Copy link
Member

@tclem tclem commented Mar 27, 2024

Fixes #17

Implements a basic way to share data between http middleware (which is dealing with raw http:Request/http::Response) and twirp RPC handlers (which are primarily concerned with implementing the service's business logic).

🙇🏻 to @nickpresta for some excellent collaboration. Thanks Nick! See #17 for the full exploration of the various options for supporting this feature.

NOTE: This is a breaking change. To migrate, users of twirp-rs must add a context param to all methods on their api server implementations. For example, this is the patch in a simple service with one rpc:

-    async fn make_hat(&self, req: MakeHatRequest) -> Result<MakeHatResponse, TwirpErrorResponse> {
+    async fn make_hat(&self, ctx: twirp::Context, req: MakeHatRequest) -> Result<MakeHatResponse, TwirpErrorResponse> {

Co-Authored-By: Nick Presta <nick.presta@shopify.com>
@tclem tclem requested a review from a team as a code owner March 27, 2024 21:51
Copy link
Contributor

@nickpresta nickpresta left a comment

Choose a reason for hiding this comment

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

Looks great! I've confirmed this works as expected with my codebase and supports the features needed to close out #17

Thanks again for all your time and patience getting to this change.

@jorendorff
Copy link
Contributor

I'll review this today.

Copy link
Contributor

@jorendorff jorendorff left a comment

Choose a reason for hiding this comment

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

👍

crates/twirp/src/context.rs Outdated Show resolved Hide resolved
Co-authored-by: Jason Orendorff <jorendorff@github.com>
@tclem tclem merged commit 6f90763 into main Mar 28, 2024
2 checks passed
@tclem tclem deleted the tclem/extensions branch March 28, 2024 21:35
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.

[Question] Request/Response Access in Handler
3 participants