-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapi.py
More file actions
37 lines (28 loc) · 898 Bytes
/
api.py
File metadata and controls
37 lines (28 loc) · 898 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
27
28
29
30
31
32
33
34
35
36
37
from apiflask import APIFlask, Schema, abort
from apiflask.fields import Integer, String
from apiflask.validators import Length, OneOf
app = APIFlask(__name__, docs_path="/apidocs", root_path="shapi")
class ShortDurationOut(Schema):
total = Integer()
class LongDurationOut(Schema):
total = Integer()
@app.get('/health_check')
def health_check():
# returning a dict or list equals to use jsonify()
return {'health': 'SUPER UP!'}
@app.get('/long_duration')
@app.output(LongDurationOut)
def long_duration():
total = 0
for i in range(0,100000000):
total += i
return {"total" : total}
@app.get('/short_duration')
@app.output(ShortDurationOut)
def short_duration():
total = 0
for i in range(0,1000):
total += i
return {"total" : total}
if __name__ == "__main__": # pragma: no cover
app.run(port=5000, debug=False, use_reloader=False)