- Notifications
You must be signed in to change notification settings - Fork 57
Expand file tree
/
Copy pathapp.py
More file actions
Latest commit
35 lines (25 loc) · 739 Bytes
/
Copy pathapp.py
File metadata and controls
35 lines (25 loc) · 739 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
fromflaskimportFlask, jsonify, abort
days= [
{"id": 1, "name": "Monday"},
{"id": 2, "name": "Tuesday"},
{"id": 3, "name": "Wednesday"},
{"id": 4, "name": "Thursday"},
{"id": 5, "name": "Friday"},
{"id": 6, "name": "Saturday"},
{"id": 7, "name": "Sunday"},
]
app=Flask(__name__)
@app.route("/", methods=["GET"])
defget_days():
returnjsonify(days)
@app.route("/<int:day_id>", methods=["GET"])
defget_day(day_id):
day= [dayfordayindaysifday["id"] ==day_id]
iflen(day) ==0:
abort(404)
returnjsonify({"day": day[0]})
@app.route("/", methods=["POST"])
defpost_days():
returnjsonify({"success": True}), 201
if__name__=="__main__":
app.run(debug=True)