[Add] sync request function of RestClient
This commit is contained in:
parent
9622d10186
commit
66cdf33b23
@ -30,7 +30,7 @@ class Request(object):
|
||||
params: dict,
|
||||
data: dict,
|
||||
headers: dict,
|
||||
callback: Callable,
|
||||
callback: Callable = None,
|
||||
on_failed: Callable = None,
|
||||
on_error: Callable = None,
|
||||
extra: Any = None,
|
||||
@ -284,3 +284,41 @@ class RestClient(object):
|
||||
"""
|
||||
url = self.url_base + path
|
||||
return url
|
||||
|
||||
def request(
|
||||
self,
|
||||
method: str,
|
||||
path: str,
|
||||
params: dict = None,
|
||||
data: dict = None,
|
||||
headers: dict = None,
|
||||
):
|
||||
"""
|
||||
Add a new request.
|
||||
:param method: GET, POST, PUT, DELETE, QUERY
|
||||
:param path:
|
||||
:param params: dict for query string
|
||||
:param data: dict for body
|
||||
:param headers: dict for headers
|
||||
:return: requests.Response
|
||||
"""
|
||||
request = Request(
|
||||
method,
|
||||
path,
|
||||
params,
|
||||
data,
|
||||
headers
|
||||
)
|
||||
request = self.sign(request)
|
||||
|
||||
url = self.make_full_url(request.path)
|
||||
|
||||
response = requests.request(
|
||||
request.method,
|
||||
url,
|
||||
headers=request.headers,
|
||||
params=request.params,
|
||||
data=request.data,
|
||||
proxies=self.proxies,
|
||||
)
|
||||
return response
|
||||
|
Loading…
Reference in New Issue
Block a user