Pengantar API di Python
Chris Ramakers
Engineering Manager


1XX: Respons informasional2XX: Respons berhasil3XX: Pesan pengalihan4XX: Kesalahan client5XX: Kesalahan server200: OK404: Not Found500: Internal Server Error
key1: Value 1
key2: Value 2

accept: application/json ke requestcontent-type: application/json# Menambahkan header ke request
response = requests.get(
'https://api.datacamp.com',
headers={'accept':'application/json'}
)
# Membaca header response
response.headers['content-type']
'application/json'
response.headers.get('content-type')
'application/json'
# Mengakses kode status response = requests.get('https://api.datacamp.com/users/12')response.status_code == 200
True
# Melihat referensi kode status dengan requests.codes response = requests.get('https://api.datacamp.com/this/is/the/wrong/path')response.status_code == requests.codes.not_found
True
Pengantar API di Python