-
Notifications
You must be signed in to change notification settings - Fork 82
/
Copy pathapp.py
66 lines (51 loc) · 1.39 KB
/
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
from flask import Flask
from flask_combo_jsonapi import Api
from combojsonapi.event import EventPlugin
from combojsonapi.spec import ApiSpecPlugin
from combojsonapi.permission import PermissionPlugin
from models.database import db
from views import PersonList, PersonDetail, ComputerList, ComputerDetail, PersonRelationship
app = Flask(__name__)
app.config.from_object("config.DevelopmentConfig")
db.init_app(app)
api_spec_plugin = ApiSpecPlugin(
app=app,
tags={
"Person": "Persons API",
"Computer": "Computers API",
},
)
event_plugin = EventPlugin(trailing_slash=False)
permission_plugin = PermissionPlugin(strict=False)
api = Api(
app,
plugins=[
event_plugin,
api_spec_plugin,
# permission_plugin,
],
)
api.route(
PersonList, "person_list", "/persons", tag="Person")
api.route(
PersonDetail,
"person_detail",
"/persons/<int:id>",
# "/computers/<int:computer_id>/owner",
tag="Person",
)
api.route(
PersonRelationship,
"person_computers",
"/persons/<int:id>/relationships/computers",
)
api.route(
ComputerList, "computer_list", "/computers", tag="Computer")
api.route(
ComputerDetail, "computer_detail", "/computers/<int:id>", tag="Computer")
@app.route("/")
def hello():
db.create_all() # use for only for dev
return {"message": "Hello world!"}
if __name__ == "__main__":
app.run()