-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
30 lines (26 loc) · 819 Bytes
/
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
from flask import Flask
from flask import request
from flask import jsonify
from flask_expects_json import expects_json
import datetime
app = Flask(__name__)
schema = {
"type": "object",
"properties": {
"firstname": { "type": "string" },
"lastname": { "type": "string" },
"age": {"type": "number"}
},
"required": ["firstname"]
}
@app.route('/')
def hello_world():
return 'Hello, World!'
@app.route("/json", methods=['POST'])
@expects_json(schema)
def read_json():
timestamp = datetime.datetime.now().isoformat()
if 'lastname' in request.json:
return jsonify({"greeting": "Hello, " + request.json['firstname']+" "+request.json['lastname'], "timestamp":timestamp})
else:
return jsonify({"greeting": "Hello, " + request.json['firstname'], "timestamp":timestamp})