Skip to content

Add option to select HTTP client type#1079

Closed
wfchandler wants to merge 2 commits intomainfrom
wc/middleware-gen
Closed

Add option to select HTTP client type#1079
wfchandler wants to merge 2 commits intomainfrom
wc/middleware-gen

Conversation

@wfchandler
Copy link
Copy Markdown
Contributor

Currently reqwest::Client is the only type we allow as the underlying HTTP client. Some consumers of Progenitor may want to use reqwest_middleware to enable conveniences like automatic retries and support for tracing.

Add a new with_client_type argument for GenerationSettings to allow callers to select which of these types to use as the client.

Currently `reqwest::Client` is the only type we allow as the underlying
HTTP client. Some consumers of Progenitor may want to use
`reqwest_middleware` to enable conveniences like automatic retries and
support for `tracing`.

Add a new `with_client_type` argument for `GenerationSettings` to allow
callers to select which of these types to use as the client.
Reqwest added the `from_parts` and `build_split` methods on
`RequestBuilder` for wasm targets with v0.12.5.

Bump Reqwest on the wasm example to that version.
Copy link
Copy Markdown
Collaborator

@ahl ahl left a comment

Choose a reason for hiding this comment

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

I think there are significant obstacles to consider. For example, I don't think reqwest-middleware should become a dependency in omicron.

I would suggest we consider other approaches to allow for more inspection of CLI requests.

format!("bytes = \"{}\"", DEPENDENCIES.bytes),
format!("futures-core = \"{}\"", DEPENDENCIES.futures),
format!("reqwest = {{ version = \"{}\", default-features=false, features = [\"json\", \"stream\"] }}", DEPENDENCIES.reqwest),
format!("reqwest-middleware = {{ version = \"{}\", default-features=false, features = [\"json\"] }}", DEPENDENCIES.reqwest_middleware),
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I don't think we want to always include this dependency.

futures-core = { workspace = true }
percent-encoding = { workspace = true }
reqwest = { workspace = true }
reqwest-middleware = { workspace = true }
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I don't think this should be a mandatory dependency

description = "An OpenAPI client generator - client support"

[dependencies]
anyhow = { workspace = true }
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This feels like a step in the wrong direction. If we need a generic error, could we use Box?

Comment on lines +125 to +130
impl Default for ClientType {
fn default() -> Self {
Self::Reqwest
}
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I thought you could derive default on enums and use a marker annotation

Comment on lines +432 to +433
ClientType::Reqwest => quote! { reqwest::Client },
ClientType::ReqwestMiddleware => quote! { reqwest_middleware::ClientWithMiddleware },
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Suggested change
ClientType::Reqwest => quote! { reqwest::Client },
ClientType::ReqwestMiddleware => quote! { reqwest_middleware::ClientWithMiddleware },
ClientType::Reqwest => quote! { ::reqwest::Client },
ClientType::ReqwestMiddleware => quote! { ::reqwest_middleware::ClientWithMiddleware },

hyper = { workspace = true }
progenitor-client = { workspace = true }
reqwest = { workspace = true }
reqwest-middleware = { workspace = true }
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

what fails if this is not present?

@wfchandler
Copy link
Copy Markdown
Contributor Author

I think I can get this working with pre and post hooks, closing this out.

@eflukx
Copy link
Copy Markdown

eflukx commented Jan 28, 2026

Supporting ReqwestClientWithMiddleware would make sense if you'd ask me.

I'm trying to implement a client for an API that requires OAuth2 token requests and renewals. Currently having a hard time doing so as progenitor requires the reqwest::Client type. Currently trying to implement this using hooks. I personally prefer to use a pre-generated client over the macro generation, but afaik that doesn't support hooks. Using reqwest middleware would be the nicest solution to this IMO.

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.

3 participants