Skip to content

PolunLin/flask-docker-task

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Flask docker task

About

  • 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

Table of contents

Repository struct

.
├── 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

Installation

pip install -r requirments.txt

Usage

  1. You can execute it by run

    python manage.py
    
  2. Use Dockerfile to create image

    docker image build -t gogolook .
    docker run -d -p 8080:8080 --name flask_app gogolook
    

Result

  1. GET /tasks (list tasks)

    curl -X GET "localhost:8080/tasks"
    

    Response

    {
        "result": [
            {"id": 1, "name": "name", "status": 0}
        ]
    }
  2. POST /task (create task)

    curl -X POST \
    -H "Content-Type: application/json" \
    -d '{"name": "買晚餐"}' \
    "localhost:8080/task"
    

    Response

    {
        "result": {"name": "買晚餐", "status": 0, "id": 1}
    }
  3. 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
    }
    }
  4. DELETE /task/ (delete task)

    curl -X DELETE "localhost:8080/task/1" 
    {
    "result": {
        "msg": "Delete id 1 successfully"
    }
    }