add params support in fetch_json

This commit is contained in:
2024-10-19 22:23:51 +08:00
parent 80b630d28d
commit 62a2820af3
+4 -4
View File
@@ -11,8 +11,8 @@ async def close_client(_client: AsyncClient) -> None:
return await _client.aclose() return await _client.aclose()
async def fetch_json(_client: AsyncClient, url: str) -> dict: async def fetch_json(_client: AsyncClient, url: str, params: dict = None) -> dict:
response = await _client.get(url) response = await _client.get(url, params=params)
assert response.is_success, f"Failed to fetch {url}, status code {response.status_code}" assert response.is_success, f"Failed to fetch {url}, status code {response.status_code}"
return response.json() return response.json()
@@ -33,5 +33,5 @@ class NetClient:
return cls._httpx_client return cls._httpx_client
@classmethod @classmethod
async def fetch_json(cls, url: str) -> dict: async def fetch_json(cls, url: str, params: dict = None) -> dict:
return await fetch_json(cls._httpx_client, url) return await fetch_json(cls._httpx_client, url, params)