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
- GET
/health— statut du service - GET
/api/livres— liste (filtre?genre=roman) - GET
/api/livres/:id— détail - POST
/api/livres— créer{titre, auteur, genre, annee} - PUT
/api/livres/:id— mettre à jour - DELETE
/api/livres/:id— supprimer
🚀 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