forked from irixjp/openstack-sample-app
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rest.py
36 lines (26 loc) · 785 Bytes
/
rest.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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import json
from flask import Flask, jsonify, request
import model
from db import db
app = Flask(__name__)
@app.route('/bbs', methods=['GET'])
def get_content():
data = {}
for i in model.get_content_all():
data[i.id] = {'timestamp': i.timestamp.strftime('%Y-%m-%d %H:%M:%S'),
'text': i.text.encode('utf-8')}
response = jsonify(data)
response.status_code = 200
return response
@app.route('/bbs', methods=['POST'])
def add_content():
ret = json.loads(request.data)
model.add_content(ret['text'])
response = jsonify(ret)
response.status_code = 201
return response
if __name__ == '__main__':
db.create_all()
app.run(host="0.0.0.0", port=5555, debug=True)