-
Notifications
You must be signed in to change notification settings - Fork 795
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ffc4b35
commit 1ef67f9
Showing
1 changed file
with
24 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
from typing import Any | ||
|
||
import httpx | ||
|
||
|
||
class AsyncHttpClient: | ||
""" | ||
A wrapper of httpx client. | ||
Functionalities: | ||
1. It comes with a default httpx.AsyncClient instance. | ||
2. The httx client could be replaced by a set_client method. | ||
""" | ||
|
||
def __init__(self, proxy: str | None = None) -> None: | ||
self.client = httpx.AsyncClient(proxy=proxy) | ||
|
||
async def get(self, url: str) -> httpx.Response: | ||
return await self.client.get(url) | ||
|
||
async def post(self, url: str, data: dict[Any, Any] | None = None) -> httpx.Response: | ||
return await self.client.post(url, data=data) | ||
|
||
async def close(self) -> None: | ||
await self.client.aclose() |