I need a function that makes a http request (get, post etc) based on the input into the function without using a bunch of if statements
Eg. I have a function:
def http_request(URI, type, data=None):
if type == "get":
requests.get(URI)
elif type == "post":
requests.post(URI, data)
I want instead for the function to get more general and pass in 'get' or 'post' as functions so i wouldn't have to use if statements, like so:
def http_request(func, URI):
r = requests.func(URI)
Needs to handle parameters for all types of http requests
Is this possible?
Thanks.