Introduction aux API en Python
Chris Ramakers
Engineering Manager


| Méthode | Facilité de mise en œuvre | Niveau de sécurité |
|---|---|---|
| Authentification Basic | ⭐ ⭐ ⭐ ⭐ ⭐ | ⭐ ☆ ☆ ☆ ☆ |
| Clé/jeton d’API | ⭐ ⭐ ⭐ ⭐ ☆ | ⭐ ⭐ ☆ ☆ ☆ |
| Authentification JWT | ⭐ ⭐ ⭐ ☆ ☆ | ⭐ ⭐ ⭐ ⭐ ☆ |
| OAuth 2.0 | ⭐ ⭐ ☆ ☆ ☆ | ⭐ ⭐ ⭐ ⭐ ⭐ |
Astuce : consultez la documentation de l’API utilisée pour savoir quelle méthode d’authentification employer !

# Ajoute automatiquement un en-tête Basic Auth avant l’envoi
requests.get('http://api.music-catalog.com', auth=('username', 'password'))
http://api.music-catalog.com/albums?access_token=faaa1c97bd3f4bd9b024c708c979feca
params = {'access_token': 'faaa1c97bd3f4bd9b024c708c979feca'}
requests.get('http://api.music-catalog.com/albums', params=params)

headers = {'Authorization': 'Bearer faaa1c97bd3f4bd9b024c708c979feca'}
requests.get('http://api.music-catalog.com/albums', headers=headers)
Introduction aux API en Python