-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
38 lines (27 loc) · 903 Bytes
/
main.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
36
37
38
from flask import Flask, request, jsonify
app = Flask(__name__)
@app.route('/get-user/<user_id>')
def get_user(user_id):
user_data = {
'user_id': user_id,
'name': 'John Doe',
'email': 'john.doe@example.com'
}
extra = request.args.get('extra')
if extra:
user_data['extra'] = extra
return jsonify(user_data), 200
@app.route('/create-user', methods=['POST'])
def create_user():
data = request.get_json()
if not data:
return jsonify({'error': 'No user data provided'}), 400
user_id = data.get('user_id')
name = data.get('name')
email = data.get('email')
if not user_id or not name or not email:
return jsonify({'error': 'Invalid user data provided'}), 400
data['status'] = 'created'
return jsonify(data), 201
if __name__ == '__main__':
app.run(debug=True)