forked from miguelgrinberg/REST-tutorial
-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathmain.py
More file actions
executable file
·89 lines (68 loc) · 2.41 KB
/
main.py
File metadata and controls
executable file
·89 lines (68 loc) · 2.41 KB
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#!flask/bin/python
from flask import Flask, jsonify, abort, request, make_response, url_for
from flask_httpauth import HTTPBasicAuth
from flask_pymongo import PyMongo
app = Flask(__name__, static_url_path="")
auth = HTTPBasicAuth()
app.config['MONGO_DBNAME'] = 'restdb'
app.config['MONGO_URI'] = 'mongodb://localhost:27017/prtdb'
mongo_mgr = PyMongo(app)
@auth.error_handler
def unauthorized():
# return 403 instead of 401 to prevent browsers from displaying the default
# auth dialog
return make_response(jsonify({'error': 'Unauthorized access'}), 403)
@app.errorhandler(400)
def bad_request(error):
return make_response(jsonify({'error': 'Bad request'}), 400)
@app.errorhandler(404)
def not_found(error):
return make_response(jsonify({'error': 'Not found'}), 404)
@app.route('/prt/api/v1.0/users', methods=['GET'])
@auth.login_required
def get_users():
"""
Update this to return a json stream defining a listing of the users
Note: Always return the appropriate response for the action requested.
"""
return jsonify({})
@app.route('/prt/api/v1.0/users/<int:user_id>', methods=['GET'])
@auth.login_required
def get_user(user_id):
return jsonify({})
@app.route('/prt/api/v1.0/users', methods=['POST'])
@auth.login_required
def create_user():
"""
Should add a new user to the users collection, with validation
note: Always return the appropriate response for the action requested.
"""
return jsonify({})
@app.route('/prt/api/v1.0/users/<int:user_id>', methods=['PUT'])
@auth.login_required
def update_user(user_id):
"""
Update user specified with user ID and return updated user contents
Note: Always return the appropriate response for the action requested.
"""
return jsonify({})
@app.route('/prt/api/v1.0/users/<int:user_id>', methods=['DELETE'])
@auth.login_required
def delete_user(user_id):
"""
Delete user specified in user ID
Note: Always return the appropriate response for the action requested.
"""
return jsonify({})
@app.route('/prt/api/v1.0/distances', methods=['GET'])
@auth.login_required
def get_distances():
"""
Each user has a lat/lon associated with them. Determine the distance
between each user pair, and provide the min/max/average/std as a json response.
This should be GET only.
You can use numpy or whatever suits you
"""
return jsonify({})
if __name__ == '__main__':
app.run(debug=True)