forked from programming-languages-38562/python-flask-api
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
26 lines (20 loc) · 634 Bytes
/
app.py
File metadata and controls
26 lines (20 loc) · 634 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
from flask import Flask
from flask_restful import Api
from models import db
from controller import LibraryResource, LibraryListResource
app = Flask(__name__)
api = Api(app)
# DB Configuration
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///test.db'
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
# Initialize DB
db.init_app(app)
# Create tables once when the app starts
@app.before_request
def create_tables():
db.create_all()
# Library routes
api.add_resource(LibraryListResource, '/api/library')
api.add_resource(LibraryResource, '/api/library/<string:isbn>')
if __name__ == "__main__":
app.run(debug=True)