Skip to content

About

Tasks Manager REST API in Python

Resources

Stars

1 star

Watchers

1 watching

Forks

Latest commit

 

History

82 Commits

Folders and files

Repository files navigation

Tasks API in Python

This is a RESTful API application for managing tasks and issues. The technology used here is Python, and the main purpose of this project is to showcase my understanding of key features under this technology, such as:

  • Requests performing CRUD operations
  • User registration and authentication using JWT
  • Some basics business rules enforced
  • Migrations and model relationship
  • Authentication configuration
  • Routes definitions
  • SOLID and KISS principles on a MVC architecture
  • Unit/Integration testing

The main tech behind it is Python with the Flask framework, to showcase it's cleanliness and simplicity while maintaning a robust architecture. For storaging i'm using relational databases managed with SQLAlchemy

Environment setup

To run this application you must have installed on your environment:

  • Python (3.1) - For the main application
  • MySQL (5.7 or greater) or PostgreSQL (15 or greater) - For storaging and accessing data

Installation and Configuration

Once all required software is up and running, execute the following commands:

python -m venv venv
source venv/Scripts/activate
pip install -r requirements.txt

If no error is thrown, the basic environment is installed. Now you must generate the database and table, but before that you must have MySQL Server running and receiving connections. Once you make sure of that, run the following:

cp .env.example .env

Open the newly created .env file and on the DB_URL parameter replace the keywords on the {}'s for your database connection information.

Having done that, just save the file then go back to the prompt and run the following:

flask shell
from app import database
from models import *
database.create_all()
exit()

If there's no big red error messages screaming at you, then you are good to go. All you have to do now is run:

flask run

And you're ready to use the API!

Tests

Before running the integration tests to validate the application's features, you must migrate the databases dedicated to tests. This depends on your .env configuration, if the ENVIRONMENT value isn't set the app will assume you're running in dev/prod enviroment. But if you need to run tests, set the ENVIRONMENT to testing and configure DB_URL_TESTING accordingly. To run the tests, simply use:

pytest

Usage

Users

User creation

curl --location 'http://localhost:5000/register' \
--header 'Content-Type: application/json' \
--data-raw '{
    "name": "T. Soprano",
    "email": "t.soprano@mail.com",
    "password": "123456"
}'

User authentication

curl --location 'http://localhost:5000/login' \
--header 'Content-Type: application/json' \
--data-raw '{
    "username": "t.soprano@mail.com",
    "password": "123456"
}'

Tasks

The User Authetication endpoint will authenticate the user, and retrieve an authorization token to be used on all the tasks related requests. Copy it and place it on all {token} keyword on the following requests

Creating a new Task

curl --location 'http://localhost:5000/api/task/create' \
--header 'Authorization: Bearer {token}' \
--header 'Content-Type: application/json' \
--data '{
    "title": "This is a title",
    "description": "Here is a description",
    "type": "hotfix"
}'

Selecting a single Task

curl --location 'http://localhost:5000/api/task/view/{taskId}' \
--header 'Authorization: Bearer {token}'

Listing all Tasks

Replace {created_by} with a User Id
Replace {status} with any of the following: new, in_qa, in_dev, blocked, closed
Replace {type} with any of the following: feature, bugfix, hotfix

curl --location 'http://localhost:5000/api/task/list?type={type}&status={status}' \
--header 'Authorization: Bearer {token}'

Updating a Task

curl --location --request PUT 'http://localhost:5000/api/task/update/{taskId}' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer {token}' \
--data '{
    "status": "in_qa"
}'

Deleting a Task

curl --location --request DELETE 'http://localhost:5000/api/task/delete/{taskId}' \
--header 'Authorization: Bearer {token}'

Closing a Task

curl --location --request PUT 'http://localhost:5000/api/task/close/{taskId}' \
--header 'Authorization: Bearer {token}'

About

Tasks Manager REST API in Python

Resources

Stars

1 star

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages