Skip to content

Create internal httpx client rather than having users pass it in #86

@Robin5605

Description

@Robin5605

I think it might be a better design choice to have the HTTP client encapsulated within the PyPIServices class, and for it to configure it however it needs. The code itself will also look cleaner:

if package_version is not None:
url = f"https://pypi.org/pypi/{package_title}/{package_version}/json"
else:
url = f"https://pypi.org/pypi/{package_title}/json"

The duplicated base URLs can be extracted into the configuration for the HTTP client.

With regard to testing, perhaps you could accept a HTTP client factory method rather than accepting the object directly instead. The default factory would be httpx.Client/httpx.AsyncClient, and tests can pass in a mock that would override it to whatever else.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions