接口请求的封装

进行请求接口的封装

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
class APIClient:
def __init__(self, base_url):
# 设置基础访问地址
self.base_url = base_url
# 保持会话
self.session = requests.session()

def get(self, url, **kwargs):
return self.session.request('GET', self.base_url+url, **kwargs)

def post(self, url, data=None, json=None, **kwargs):
return self.session.request('POST', self.base_url+url, data, json, **kwargs)

def put(self, url, data=None, **kwargs):
return self.session.request('PUT', self.base_url+url, data, **kwargs)

def delete(self, url, **kwargs):
return self.session.request('DELETE', self.base_url+url, **kwargs)
------------- End -------------