02

API Livres — Flask CRUD

Implémentez une API REST complète pour gérer une bibliothèque de livres avec Flask. Stockage en mémoire, Blueprint, validation, gestion d'erreurs JSON.

Flask 3 Blueprint jsonify Débutant

🔌 Endpoints

🚀 Lancer la solution

cd formation-python/02-flask-bases/mini-projet/solution
pip install -r requirements.txt
python app.py
# API disponible sur http://localhost:5000

🧪 Tests curl

# Lister
curl http://localhost:5000/api/livres

# Filtrer par genre
curl "http://localhost:5000/api/livres?genre=roman"

# Créer
curl -X POST http://localhost:5000/api/livres \
  -H "Content-Type: application/json" \
  -d '{"titre":"Python Fluent","auteur":"Ramalho","genre":"technique","annee":2022}'

# Mettre à jour
curl -X PUT http://localhost:5000/api/livres/1 \
  -H "Content-Type: application/json" \
  -d '{"genre":"programmation"}'

# Supprimer
curl -X DELETE http://localhost:5000/api/livres/1
⬇ app.py ⬇ requirements.txt 📖 Revoir le cours 🧠 QCM