forked from thomaxxl/safrs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mini_app.py
executable file
·38 lines (31 loc) · 1.02 KB
/
mini_app.py
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
27
28
29
30
31
32
33
34
35
36
37
38
#!/usr/bin/env python
# run:
# $ FLASK_APP=mini_app flask run
from flask import Flask
from flask_sqlalchemy import SQLAlchemy
from safrs import SAFRSBase, SAFRSAPI
db = SQLAlchemy()
class User(SAFRSBase, db.Model):
'''
description: User description
'''
__tablename__ = 'Users'
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String)
email = db.Column(db.String)
def create_api(app, HOST='localhost', PORT=5000, API_PREFIX=''):
api = SAFRSAPI(app, host=HOST, port=PORT, prefix=API_PREFIX)
api.expose_object(User)
user = User(name='test',email='email@x.org')
print('Starting API: http://{}:{}/{}'.format(HOST,PORT,API_PREFIX))
def create_app(config_filename = None):
app = Flask('demo_app')
app.config.update( SQLALCHEMY_DATABASE_URI = 'sqlite://' )
db.init_app(app)
with app.app_context():
db.create_all()
create_api(app)
return app
if __name__ == '__main__':
app = create_app()
app.run()