Introductie tot API's in Python
Chris Ramakers
Engineering Manager


1XX: Informatieve responses2XX: Succesvolle responses3XX: Redirects4XX: Clientfouten5XX: Serverfouten200: OK404: Not Found500: Internal Server Error
key1: Value 1
key2: Value 2

accept: application/json-header toe aan de requestcontent-type: application/json-header# Headers toevoegen aan een request
response = requests.get(
'https://api.datacamp.com',
headers={'accept':'application/json'}
)
# Response-headers lezen
response.headers['content-type']
'application/json'
response.headers.get('content-type')
'application/json'
# De statuscode opvragen response = requests.get('https://api.datacamp.com/users/12')response.status_code == 200
True
# Statuscodes opzoeken via requests.codes response = requests.get('https://api.datacamp.com/this/is/the/wrong/path')response.status_code == requests.codes.not_found
True
Introductie tot API's in Python