Placeholders in base URL #2679
Answered
by
BeyondEvil
BeyondEvil
asked this question in
Q&A
|
Is it possible to provide a base URL to Client with placeholders (similar to f-strings/format)? Either named or positional? Something like: |
Answered by
BeyondEvil
Apr 26, 2023
Replies: 3 comments 1 reply
|
Yeah, that's similar to what I did, but I have a function. from httpx import Client
from syncer import config
class HTTPClient:
def __init__(self):
self._client = None
self._default_headers = {"Content-Type": "application/json"}
self._default_params = {"api-version": "7.0"}
def client(self):
if self._client is None:
self._client = Client(
auth=("", config.get("pat")),
headers=self._default_headers,
params=self._default_params,
)
return self._client
def url(org_id, project_id, endpoint):
return f"https://dev.azure.com/{org_id}/{project_id}/_apis/wit/workitems/{endpoint}"and a call might look like: response = self._http_client.delete(
url(self.org, self.project_id, self.id),
) |
1 reply
Answer selected by
lovelydinosaur
|
Would you review a PR providing this feature @tomchristie ? |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment



Yeah, that's similar to what I did, but I have a function.