Skip to content

Latest commit

 

History

History
73 lines (48 loc) · 1.58 KB

File metadata and controls

73 lines (48 loc) · 1.58 KB

Farms API

Overview

Farms dataset API management

Installation

pip install -r requirements.txt

Usage

flask --app farms_api run --debug

Testing

pytest

Code Generator

This application offer CLI functions to speed up your setup based on the principals and architecture based to build this project.

Creating routes

From root folder, execute the command line bellow. Remind to fill up with the name you want to create.

python scaffolding/generate_routes.py <name>

# Example
python scaffolding/generate_routes.py users

As the result, you will find two files generated by in your directory. Using the example above:

  • farms_api/routes/users.py contains the flask routes
  • farms_api/routes/users_tests.py contains the tests related to the routes created

Do you need to change the app configuration manually. Open farms_api/__init__.py and add your new routes paths to the main Flask application.

# farms_api/__init__.py
...

# Import the new routes created
from farms_api.routes.users import users_blueprint


def create_app(test_config=None):
    # create and configure the app
    app = Flask(__name__, instance_relative_config=True)
    app.config.from_mapping(
        SECRET_KEY='dev',
        DATABASE=os.path.join(app.instance_path, 'flaskr.sqlite'),
    )

    app.register_blueprint(farmers_blueprint, url_prefix='/api')
    app.register_blueprint(addresses_blueprint, url_prefix='/api')

    # add the new routes imported to the main app
    app.register_blueprint(users_blueprint, url_prefix='/api')


...