- Python: 3.12
- Flask: 3.0.3
- GET /health
{"status":"healthy"}
- GET /users/1
{ "id": 1, "name": "test_user1" }
- POST /users/
curl -X POST -H "Content-Type: application/json" -d '{"name": "naka", "email": "naka@example.com"}' localhost:5000/users { "id": 7, "name": "naka" }
sample/
, a Python package containing your application code and files.tests/
, a directory containing test modules.venv/
, a Python virtual environment where Flask and other dependencies are installed.
-
Prepare requirements.txt
poetry export -f requirements.txt --output requirements.txt --without-hashes
-
Run MySQL
docker-compose -f docker/docker-compose.yml up -d mysql
-
Local env
poetry install FLASK_APP=sample FLASK_ENV=development poetry run flask run
-
Check health
curl localhost:5000/health {"status":"healthy"}
-
Run test
poetry run pytest ========================================================================================== test session starts ========================================================================================== platform darwin -- Python 3.9.0, pytest-6.2.1, py-1.10.0, pluggy-0.13.1 rootdir: /Users/masato-naka/repos/nakamasato/flask-sample plugins: cov-3.0.0 collected 3 items tests/test_api.py ... [100%] =========================================================================================== 3 passed in 0.06s ===========================================================================================
-
Docker Compose
docker-compose -f docker/docker-compose.yml up # add --build if you want to rebuild
-
Curl
curl localhost:5000/health {"status":"healthy"}