Skip to content

Fix issue #8: allow injecting custom HTTP clients for advanced transport and retry logic#15

Open
Deadpool2000 wants to merge 2 commits intoopenapi:mainfrom
Deadpool2000:fix-issue-8
Open

Fix issue #8: allow injecting custom HTTP clients for advanced transport and retry logic#15
Deadpool2000 wants to merge 2 commits intoopenapi:mainfrom
Deadpool2000:fix-issue-8

Conversation

@Deadpool2000
Copy link
Copy Markdown
Contributor

Hey @francescobianco

This PR addresses an issue where the SDK was tightly coupled to its own internal instantiation of httpx clients, which made it impossible for developers to plug in custom transport adapters or specialized retry policies (like urllib3's Retry strategy).

What changed?

  • Added a custom client injection parameter: I've updated the __init__ methods for all SDK client classes (Client, AsyncClient, OauthClient, and AsyncOauthClient) to accept an optional client parameter.
  • Maintained backward compatibility: If a user doesn't pass a custom client, the SDK will safely fall back to instantiating the default httpx client just like it always has. None of the existing implementations or downstream projects will break.
  • Updated Test Suites: Added new Unit Tests matching both synchronous and asynchronous classes to guarantee that a custom-injected transport layer is correctly assigned and utilized under the hood.
  • Updated the documentation: I extended README.md with a new "Customizing the Transport Layer" section, including a practical code snippet on how to pass a requests.Session bundled with a urllib3 max-retries adapter.

Why is this important?

Providing a way to BYOC ("Bring Your Own Client") gives a lot of flexibility. It unblocks consumers of the SDK who need strict timeout rules, proxy configurations, or advanced retry strategies when interacting with our APIs in production environments.

Let me know if you have any questions or feedback.

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.

1 participant