|
7 | 7 | """
|
8 | 8 |
|
9 | 9 | import abc
|
| 10 | +import atexit |
10 | 11 | import logging
|
11 | 12 | import re
|
12 | 13 | import uuid
|
@@ -73,9 +74,7 @@ def __init__(
|
73 | 74 | transport=transport,
|
74 | 75 | )
|
75 | 76 |
|
76 |
| - @abc.abstractmethod |
77 |
| - def _client_factory(self, **kwargs) -> Union[httpx.Client, httpx.AsyncClient]: |
78 |
| - """Create a new HTTP client instance with the provided settings.""" |
| 77 | + atexit.register(self.close) |
79 | 78 |
|
80 | 79 | @property
|
81 | 80 | def base_url(self) -> str:
|
@@ -116,6 +115,75 @@ def get_application_headers(self, overrides: Union[dict, None] = None) -> dict[s
|
116 | 115 |
|
117 | 116 | return headers
|
118 | 117 |
|
| 118 | + @abc.abstractmethod |
| 119 | + def _client_factory(self, **kwargs) -> Union[httpx.Client, httpx.AsyncClient]: |
| 120 | + """Create a new HTTP client instance with the provided settings.""" |
| 121 | + |
| 122 | + @abc.abstractmethod |
| 123 | + def close(self) -> None: |
| 124 | + """Close any open server connections.""" |
| 125 | + |
| 126 | + @abc.abstractmethod |
| 127 | + def send_request( |
| 128 | + self, |
| 129 | + method: HttpMethod, |
| 130 | + endpoint: str, |
| 131 | + *, |
| 132 | + headers: Optional[dict] = None, |
| 133 | + json: Optional[RequestContent] = None, |
| 134 | + files: Optional[RequestFiles] = None, |
| 135 | + params: Optional[QueryParamTypes] = None, |
| 136 | + timeout: int = httpx.USE_CLIENT_DEFAULT, |
| 137 | + ) -> httpx.Response: |
| 138 | + """Send an HTTP request (sync or async depending on the implementation).""" |
| 139 | + |
| 140 | + @abc.abstractmethod |
| 141 | + def http_get( |
| 142 | + self, |
| 143 | + endpoint: str, |
| 144 | + params: Optional[QueryParamTypes] = None, |
| 145 | + timeout: int = httpx.USE_CLIENT_DEFAULT, |
| 146 | + ) -> httpx.Response: |
| 147 | + """Send a GET request.""" |
| 148 | + |
| 149 | + @abc.abstractmethod |
| 150 | + def http_post( |
| 151 | + self, |
| 152 | + endpoint: str, |
| 153 | + json: Optional[RequestData] = None, |
| 154 | + files: Optional[RequestFiles] = None, |
| 155 | + timeout: int = httpx.USE_CLIENT_DEFAULT, |
| 156 | + ) -> httpx.Response: |
| 157 | + """Send a POST request.""" |
| 158 | + |
| 159 | + @abc.abstractmethod |
| 160 | + def http_patch( |
| 161 | + self, |
| 162 | + endpoint: str, |
| 163 | + json: Optional[RequestData] = None, |
| 164 | + files: Optional[RequestFiles] = None, |
| 165 | + timeout: int = httpx.USE_CLIENT_DEFAULT, |
| 166 | + ) -> httpx.Response: |
| 167 | + """Send a PATCH request.""" |
| 168 | + |
| 169 | + @abc.abstractmethod |
| 170 | + def http_put( |
| 171 | + self, |
| 172 | + endpoint: str, |
| 173 | + json: Optional[RequestData] = None, |
| 174 | + files: Optional[RequestFiles] = None, |
| 175 | + timeout: int = httpx.USE_CLIENT_DEFAULT, |
| 176 | + ) -> httpx.Response: |
| 177 | + """Send a PUT request.""" |
| 178 | + |
| 179 | + @abc.abstractmethod |
| 180 | + def http_delete( |
| 181 | + self, |
| 182 | + endpoint: str, |
| 183 | + timeout: int = httpx.USE_CLIENT_DEFAULT, |
| 184 | + ) -> httpx.Response: |
| 185 | + """Send a DELETE request.""" |
| 186 | + |
119 | 187 |
|
120 | 188 | class HTTPClient(HTTPBase):
|
121 | 189 | """Synchronous HTTP Client."""
|
|
0 commit comments