1
- from typing import Optional
1
+ from typing import Any , Dict , Optional , Union
2
2
3
3
import requests
4
+ from requests_toolbelt .multipart .encoder import MultipartEncoder # type: ignore
4
5
5
6
6
7
class RequestsBackend :
@@ -10,3 +11,40 @@ def __init__(self, session: Optional[requests.Session] = None) -> None:
10
11
@property
11
12
def client (self ) -> requests .Session :
12
13
return self ._client
14
+
15
+ def http_request (
16
+ self ,
17
+ method : str ,
18
+ url : str ,
19
+ json : Optional [Union [Dict [str , Any ], bytes ]] = None ,
20
+ data : Optional [Union [Dict [str , Any ], MultipartEncoder ]] = None ,
21
+ params : Optional [Any ] = None ,
22
+ timeout : Optional [float ] = None ,
23
+ verify : Optional [Union [bool , str ]] = True ,
24
+ stream : Optional [bool ] = False ,
25
+ ** kwargs : Any
26
+ ) -> requests .Response :
27
+ """Make HTTP request
28
+
29
+ Args:
30
+ method: The HTTP method to call ('get', 'post', 'put', 'delete')
31
+ url: Path or full URL
32
+ stream: Whether the data should be streamed
33
+ files: The files to send to the server
34
+ timeout: The timeout, in seconds, for the request
35
+ json: Data to send in the body in json by default
36
+
37
+ Returns:
38
+ A requests Response object.
39
+ """
40
+ return self ._client .request (
41
+ method = method ,
42
+ url = url ,
43
+ params = params ,
44
+ data = data ,
45
+ timeout = timeout ,
46
+ stream = stream ,
47
+ verify = verify ,
48
+ json = json ,
49
+ ** kwargs
50
+ )
0 commit comments