Skip to content

sorin-sabo/Flask-Rest-Api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Flask REST API

1. Functionalities covered:
-   Rest API CRUD opertaions;
-   Oauth2 integration handling both id and access token;
-   Validation for request data using dtos and schemas;
-   Unit tests with a mixin of unittest & pytest
-   API docs with swagger;
-   Code quality assured with pylint;
2. Programming principles covered:
-   Best practices in Flask;
-   Geneneric response format;
-   Custom error handling for all response types;

Requirements

It is assumed that:

  • You have Python and MySQL installed. If not, then download the latest versions from:

Installation

  1. Clone git repository:

    git clone https://github.com/sorin-sabo/Flask-Rest-Api.git
  2. Create virtual environment

    • Windows
    python -m venv $(pwd)/venv
    source venv/bin/activate
    • OS X
    python3 -m venv $(pwd)/venv
    source venv/bin/activate
  3. Install requirements:

    • Windows
    pip install -r requirements.txt
    • OS X
    pip3 install -r requirements.txt
  4. Add environment variables

    • Create a file named .env in project root directory
    • Add and fill next environment variables with your local database config:
      DATABASE_USERNAME=
      DATABASE_PASSWORD=
      DATABASE_NAME=
      DATABASE_PORT=
      DATABASE_HOST=
      OAUTH2_DOMAIN=
      OAUTH2_GUEST=
      OAUTH2_CLIENT=

Run

  • Application can run directly from cmd using fallowing commands:
    • Using python run

      • Windows
      python app.py run
      • OS X
      python3 app.py run
    • Using flask run

    flask run

Test

  • Tests are done with a mixin of unittest & pytest
    • A base class is created for all unit tests to inherit and can be found in tests/utils/base - BaseTestCase
  • Run:
    • Method1:

      • Windows:
      python app.py test
      • OS X:
      python3 app.py test
    • Method2 - Using pytest:

      • For fallowing options are available:

        • -v - to have verbose tests
        • -s - to see logging from tests
      • Windows:

      pytest tests
      • OS X:
      pytest -q tests

Migrate on data model changes

  • Run fallowing commands

    • Windows
    python app.py db init
    python app.py db migrate
    python app.py db upgrade
    • OS X
    python3 app.py db init
    python3 app.py db migrate
    python3 app.py db upgrade

Useful

  • Before deploy check package dependencies (since 2020 Dec 01 is no longer done automatically):
    python -m pip check

Code quality

  • Pylint used to maintain code quality;
  • Rules for code quality can be consulted in .pylintrc
  • Current status: Your code has been rated at 10.00/10 (previous run: 10.00/10, +0.00)
  • Make sure before deployment that code quality is the same;

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages