Add setting to configure API base URL #42
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This pull request proposes adding a setting to configure the base URL of the PwnedPasswords API, which enables a use-case that I have for using this package together with a self-hosted instance of the API.
Alternatives considered
Technically it's already possible to customize the API endpoint by overriding a class-level variable directly on the PwnedPasswords client as shown in the snippet below, but this approach to me seems unnecessarily brittle and splits configuration of the package into two locations (Django settings and code):
Instead, if this pull request is merged, a consumer of this package can simply configure the base URL in the Django settings:
Implementation notes
The proposed implementation is a little bit round-about in overriding the value of the existing class-level
api_endpoint
variable in the constructor. I considered two alternative implementations (discussed below) but believe that there's larger downsides to each of them compared to the proposed implementation.Alternative 1: access setting in the class-level variable
Upsides:
Downsides:
Alternative 2: only initialize the setting in the constructor
Upsides:
api_endpoint
be defined on both the class-level and the instance-level.Downsides:
api.PwnedPasswords.api_endpoint
existing as a class-level variable.