- Implement a Restful task list API as well as run this application in container.
- Project status: working
- enviroment: python==3.9, flask==2.0.3
- Database:sqlite3, flask_sqlalchemy
.
├── Dockerfile // create docker container
├── README.md
├── app // main application,database and setting
│ ├── __init__.py
│ └── config
│ ├── config.py // application config
│ ├── development.db
│ └── test.db // database for test
├── manage.py // application start entry
├── requirements.txt
├── task // task application
│ ├── models
│ │ └── task.py
│ └── views.py
└── unit_test.py // test file
pip install -r requirments.txt
-
You can execute it by run
python manage.py
-
Use Dockerfile to create image
docker image build -t gogolook . docker run -d -p 8080:8080 --name flask_app gogolook
-
GET /tasks (list tasks)
curl -X GET "localhost:8080/tasks"
Response
{ "result": [ {"id": 1, "name": "name", "status": 0} ] }
-
POST /task (create task)
curl -X POST \ -H "Content-Type: application/json" \ -d '{"name": "買晚餐"}' \ "localhost:8080/task"
Response
{ "result": {"name": "買晚餐", "status": 0, "id": 1} }
-
PUT /task/ (update task)
curl -X PUT \ -H "Content-Type: application/json" \ -d '{"name": "買早餐", "status": 1}' \ "localhost:8080/task/1"
Response
{ "result":{ "name": "買早餐", "status": 1, "id": 1 } }
-
DELETE /task/ (delete task)
curl -X DELETE "localhost:8080/task/1"
{ "result": { "msg": "Delete id 1 successfully" } }