Add base code for REST API using Flask

This commit is contained in:
Lexi / Zoe 2022-03-26 01:07:47 +01:00
parent 0be947b3d1
commit 2da6e43797
Signed by: binaryDiv
GPG key ID: F8D4956E224DA232
12 changed files with 266 additions and 14 deletions

View file

@ -1,10 +1,32 @@
def app(environ, start_response):
"""Simplest possible application object"""
data = b'Hello, wooorld!\n'
status = '200 OK'
response_headers = [
('Content-type', 'text/plain'),
('Content-Length', str(len(data)))
]
start_response(status, response_headers)
return iter([data])
import os
import yaml
from flask import Flask
from tofu_api.api import TofuApiBlueprint
from tofu_api.config import DefaultConfig
def create_app() -> Flask:
"""
App factory, returns a Flask app object.
"""
# Set instance path to the project root directory
project_root_dir = os.path.abspath('.')
# Create and configure the app
app = Flask(
'tofu_api',
instance_path=project_root_dir,
instance_relative_config=True,
)
app.config.from_object(DefaultConfig)
# Load app configuration from YAML file
app.config.from_file(os.getenv('FLASK_CONFIG_FILE', default='config.yml'), load=yaml.safe_load)
# Register blueprints
app.register_blueprint(TofuApiBlueprint())
# Return WSGI app
return app