Browse Source

callrestapi can also return full response object on request

PVA
Roman Steiner 3 years ago
parent
commit
fdcf9919c2
  1. 12
      sharedfunctions.py

12
sharedfunctions.py

@ -99,7 +99,7 @@ def validaterestapi(baseurl, reqval, reqtype, data={}):
# 20Feb2022 Support patch
# 28Feb2022 Added functionality to optionally pass in etags, and to request they be returned, for API endpoints that use them
def callrestapi(reqval, reqtype, acceptType='application/json', contentType='application/json',data={},header={},stoponerror=1,returnEtag=False,etagIn=''):
def callrestapi(reqval, reqtype, acceptType='application/json', contentType='application/json',data={},header={},stoponerror=1,returnEtag=False,etagIn='',returnResponse=False):
# get the url from the default profile
@ -146,7 +146,10 @@ def callrestapi(reqval, reqtype, acceptType='application/json', contentType='app
# response error if status code between these numbers
if (400 <= ret.status_code <=599):
if returnResponse:
return ret
else:
print("http response code: "+ str(ret.status_code))
print("ret.text: "+ret.text)
result=None
@ -170,9 +173,14 @@ def callrestapi(reqval, reqtype, acceptType='application/json', contentType='app
if 'etag' in ret.headers:
etagOut=ret.headers['etag']
if returnResponse:
# ONLY if the caller specifically asked for the whole resposne object, return it
return ret
elif returnEtag:
# ONLY if the caller specifically asked for an etag to be returned, return one
if returnEtag:
return result,etagOut;
else:
# Otherwise, return only the result as normal.
# This avoids breaking anything that does not expect an etag to be returned

Loading…
Cancel
Save