adds (http requests) header class
This commit is contained in:
17
src/classes.py
Normal file
17
src/classes.py
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
class Header:
|
||||||
|
'''
|
||||||
|
Class to standardize the format of the headers of our http requests.
|
||||||
|
'''
|
||||||
|
def __init__(self, apikey=""):
|
||||||
|
'''Init method, apikey suggested but not required (empty by default).'''
|
||||||
|
self.auth = {"Authorization" : apikey}
|
||||||
|
self.content = {"Content-Type" : "application/json"}
|
||||||
|
def dump(self):
|
||||||
|
'''Dumps the header in form of a dictionary.'''
|
||||||
|
dump = {**self.auth, **self.content}
|
||||||
|
return dump
|
||||||
|
|
||||||
|
if __name__=="__main__":
|
||||||
|
head = Header("MyApiKey-123456789abcdef")
|
||||||
|
print(f"Example header: {head.dump()}")
|
||||||
|
print("Warning: you're not supposed to be running this as the main program.")
|
||||||
Reference in New Issue
Block a user