pabvald / fast-api-test

Minimal API with FastAPI

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Small API

Author: Pablo Valdunciel

Date: 07/09/2022

Comments on implementation decisions

  1. Uniqueness of the username: the inclusion of the UNIQUE constraint for the username does not seem appropriate, since two people can easily have the same name, especially if it is a common name. In a real scenario, the UNIQUE constraint should be applied to the username in any case, since the username is usually used as an alternate primary key.

  2. Including the TVShow table. When it comes to representing Enums in databases, there are two possibilities:

    • Inserting a table containing the possible values of the Enum and adding a foreign key in the main table.
    • Inserting a string column in the main table

    The decision can be made based on how much space each of the two approaches takes up. In general, it is better to insert an additional table if the enum has few values, so the string column would have many repetitions.

    In this task, I chose the fastest to implement option, which is to simply insert a string column, and ignored the space complexity issue.

Execution

Command prompt

First, create a virtual environment and activate it.

python -m venv .venv
source .venv/bin/activate # (Linux) .venv/Scripts/activate (Windows)

Second, install the dependencies.

pip install -r api/requirements.txt

Finally, start the FastAPI app.

cd api
python run.py

The API is available at localhost:8080/.

Docker

Execute the following commands. To do so, it is necessary to have Docker and Docker Compose installed.

docker-compose build 
docker-compose up

The API is available at localhost:8080/.

Testing

The tests can be found in the test/ folder. To run the tests, execute the following commands:

cd api
python -m pytest ./test/

Documentation

Once the FastAPI app is running, the documentation is available under localhost/8080/redoc

Resources

About

Minimal API with FastAPI

License:GNU General Public License v3.0


Languages

Language:Python 98.8%Language:Dockerfile 1.2%