I have an API that talks to different APIs, most of them are exposed as restful web services. I am using python requests and I am using requests_toolbet to log all the requests/responses for debugging purposes. My code looks like:
def call_api(self, paramas):
print('----------> calling API')
url = self.base_url + params...
headers = {'Authorization': 'Bearer ' + BEARER_TOKEN}
resp = requests.get(url, headers=headers)
print(dump.dump_all(resp).decode('utf-8'))
return resp.json()
As you might imagine, every single request have a pretty similar code for logging:
resp = requests.get(url, headers=headers)
print(dump.dump_all(resp).decode('utf-8'))
I was wondering if there is a way that I can remove the same code using decorators or so. I am a newbie in python so any help is really appreciated.