-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapps.py
More file actions
36 lines (24 loc) · 980 Bytes
/
apps.py
File metadata and controls
36 lines (24 loc) · 980 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
import json
from flask import Flask, jsonify, request, make_response
app = Flask(__name__)
@app.route('/hello', methods=['GET'])
def hello():
return jsonify({'message': 'Hello World'})
@app.route('/ack/<param>', methods=['GET'])
def ack(param):
if not param or param.isdigit():
return make_response(jsonify({"message": "Query Param must be a string"}), 404)
return jsonify({'message': param.upper()})
@app.route('/postme', methods=['POST'])
def sample_post():
if not request.is_json:
return make_response(jsonify({"message": "Invalid Request"}), 404)
data = json.loads(request.data, strict=False)
if not data:
return make_response(jsonify({"message": "No Payload"}), 404)
if not data.get('foo'):
return make_response(jsonify({"message": "'foo' key is missing"}), 404)
data['message'] = 'Data parsed successfully'
return jsonify(data)
if __name__ == '__main__':
app.run(host='0.0.0.0', port=5000)