Skip to content

A simple project containing a set of CRUD API endpoints for a contact book application.

License

Notifications You must be signed in to change notification settings

notsatan/fast-track

Repository files navigation

Release Release Date Language License Code Size Black


fast-track

A simple project containing a set of CRUD API endpoints for a contact book application.

Explore the docs »

Bug Report · Request a Feature · Fork Repo




Index

About

A demonstration of the backend API for a contacts application. Uses Flask as the main framework.

Uses SQLite3 as the main database by default. Includes a config file allowing to switch deployment mode between debugging and production, and modify the root directory - i.e. the directory where the database and logs are to be stored

Features

The overall layout of the project has been inspired by python-package-template

Developer Features

  • Supports Python 3.6 and above
  • Uses Poetry as the dependencies manager
  • Code formatters being used: Black, iSort, PyUpgrade
  • Docstring checkers with Darglint
  • Type checks configured using MyPy
  • Includes .editorconfig file to ensure uniformity across IDE's
  • Breakdown dependencies into developer dependencies and user dependencies (the former also includes linters, code checkers, code formatters and more).

Build and Deployment

  • Uses Github Actions for CI
  • Makefile to automate tests, linters, code formatters and more (use make or make --help for info regarding the Makefile)
  • Includes pre-commit hooks to automate code formatting

Usage

For installation, it is recommended to use a Virtual Environment. Use;

make setup

This will download and install Poetry, and then install all required dependencies

Setup the config file as required, once done, rename the file from config.ini.sample to config.ini

To run the project, use

python runner.py

The python file will read values from the config, and pass them to the main project.

API Endpoints

A list of end-points to perform add, edit, delete, and search operations.

Add Contact

  • Endpoint: "/post"
  • Method: POST

Input Body:

{
    "name": "demon-rem",
    "email": "test-email@github.com",
    "phone": "007_0063"
}

Response Received:

{"email": "test-email@github.com", "name": "demon-rem", "phone_number": "007_0063"}

Note: The database enforces a unique constraint on the email and the phone number, adding an entry that attempts to duplicate either of these values will result in a 500 status code.

Remove Contact

  • Endpoint: "/delete"
  • Method: DELETE

Input Body:

{
    "email": "test-email@github.com"
}

Response Received:

{
    "result": "deleted contact successfully"
}

Note: An error will thrown if the email id does not match any existing contact(s)

Update Contact

  • Endpoint: "/update"
  • Method: POST

Input Body:

{
    "email": "007_006@gmail.com",
    "new_name": "new-user",
    "new_email": "new-email@github.com",
    "new_phone": "324451"
}

Response Received:

{
    "result": "contact modified successfully"
}

Note: In the input body, all three fields, i.e. new_name, new_email and new_phone are optional - at least one of them is required. Any missing field will not be modified in the database.

Search Contact

  • Endpoint: "/search"
  • Method: GET

Input Body:

{
    "email": "new-user@github.com",
    "name": "new-user"
}

P.S. The email and name parameter are both optional - one of them should be present. Using both of them will display results where the name matches, as well as the email ID.

Response Received:

[
    {
        "email": "new-user@github.com",
        "name": "new-user",
        "phone_number": "007324451"
    }
]

Note: In order to optimize searches, the project uses in-memory TTL based cache implemented through cachetools - search results are cached in memory for 10 seconds, and up to a 100 results.