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

Add optional reqwest-middleware feature #1074

Closed
wants to merge 1 commit into from
Closed

Conversation

wfchandler
Copy link
Contributor

Add a new middleware feature that allows users to opt into using reqwest_middleware::Client instead of reqwest::Client. This enables users to enable automatic retries or tracing in their application.

Add a new `middleware` feature that allows users to opt into using
`reqwest_middleware::Client` instead of `reqwest::Client`. This enables
users to enable automatic retries or tracing in their application.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The diff on this PR is unfortunately quite large due to duplication of each test output file with the middleware FF enabled.

@wfchandler
Copy link
Contributor Author

This will be consumed by oxidecomputer/oxide.rs#1035

@wfchandler
Copy link
Contributor Author

Do we want to update CI to run tests and/or builds with this feature enabled?

@wfchandler wfchandler requested a review from ahl February 26, 2025 17:48
@ahl
Copy link
Collaborator

ahl commented Feb 26, 2025

Can you give me context on why we're doing this and where we intend to use it?

Does this make sense as a cargo feature? Recall that features apply across the compilation so eg using this feature for one client crate would break the use of an unrelated client crate that did not intend to use the feature.

@wfchandler
Copy link
Contributor Author

Can you give me context on why we're doing this and where we intend to use it?

This enables us to generate logs for API calls in oxide.rs, see oxidecomputer/oxide.rs#1035 for the implementation.

Does this make sense as a cargo feature? Recall that features apply across the compilation so eg using this feature for one client crate would break the use of an unrelated client crate that did not intend to use the feature.

I think it's the least worst option:

  1. Replace reqwest::Client with reqwest_middleware::ClientWithMiddleware. Breaking change for all dependents of Progenitor, many of whom may not want to use middleware.
  2. Add an additional progenitor::ClientWithMiddleware that we populate with all methods we generate for progenitor::Client. Avoids the feature flag, but doubles the amount of codegen, slowing builds and bloating binaries.
  3. Feature flag for middleware, this PR. No additional codegen, dependents can opt into middleware if desired. Looking through the packages listed as dependents on crates.io, I don't see any that have multiple Progenitor clients being generated, but of course we don't know about any non-public usage.

@ahl
Copy link
Collaborator

ahl commented Feb 28, 2025

A couple of options that seem potentially palatable

  1. Settings-based configuration for codegen
  2. Abstracting the client to be a trait for which we provide impls e.g. for reqwest::Client

I don't see option 3 as viable.

@wfchandler
Copy link
Contributor Author

A couple of options that seem potentially palatable

  1. Settings-based configuration for codegen
  2. Abstracting the client to be a trait for which we provide impls e.g. for reqwest::Client

I don't see option 3 as viable.

A settings option is much cleaner, thanks! I've opened #1079, will close this out.

@wfchandler wfchandler closed this Mar 3, 2025
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