TO DO List is a simple API project created with everything that I learned on course Do Zero ao Deploy by Cássio Botaro.
This project covers the following concepts:
- Python environments with Pipenv
- Test Driven Development with PyTest
- Starting with Flask framework
- Continuous Integration with Travis
- Continuous Deployment with Heroku
Starting from what has been taught, I improved the API with MongoDB persistence.
All code was written with Python 3.6, so, for a correct running, it is recommended to install this one.
After Python installed, it is required to install all dependencies. You can use Pipenv or Virtualenv. If you are using Pipenv, use the following command to install from Pipfile:
$ pipenv install
...and active the environment:
$ pipenv shell
However, if you are using Virtualenv, you need to activate the environment and install from requirements.pip file:
$ source YOUR_ENVIRONMENT_DIRECTORY/bin/activate
$ pip install -r requirements.pip
Install MongoDB in your machine and be sure MongoDB process is running.
$ python todo.py
* Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
API Endpoints:
GET /tasks
: Return all tasks availablePOST /tasks
: Create a new task
You can test the application using the development dependencies.
Install all development dependencies from Pipfile:
$ pipenv install --dev
Or from dev-requirements.pip file if you are using VirtualEnv:
$ pip install -r dev-requirements.pip
To debug endpoints, you can use HTTPie as following:
$ http http://127.0.0.1:5000/tasks
[
{
"_id": {
"$oid": "5ad3d924e3bdea6ccf9d9d3e"
},
"description": "The Best Description",
"done": false,
"title": "The Best Title"
},
{
"_id": {
"$oid": "5ad3d8fae3bdea6c41d571f4"
},
"description": "The Incredible Description",
"done": false,
"title": "The Incredible Title"
}
]
$ http POST http://127.0.0.1:5000/tasks title=Test description=Test
HTTP/1.0 201 CREATED
Content-Length: 123
Content-Type: application/json
Date: Mon, 16 Apr 2018 00:23:45 GMT
Server: Werkzeug/0.14.1 Python/3.6.2
{
"_id": {
"$oid": "5ad3ed11e3bdea06aa7afa06"
},
"description": "Test",
"done": false,
"title": "Test"
}
To run the tests, you can use PyTest as following:
$ python -m pytest
...
collected 7 items
test_todo.py ....... [100%]
========================== 7 passed in 1.32 seconds ==========================