-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapi.py
40 lines (29 loc) · 1.06 KB
/
api.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
39
40
import flask
from flask import request, jsonify
from test import *
app = flask.Flask(__name__)
app.config["DEBUG"] = True
@app.route('/', methods=['GET'])
def home():
return '''<h1>THIS IS A TEST</h1>
<p>Test API</p>'''
@app.route('/api/v1/resources/movies/all', methods=['GET'])
def api_all():
results = get_movies_by_id()
return jsonify(results)
@app.route('/api/v1/resources/movies', methods=['GET'])
def api_id():
# Check if an ID was provided as part of the URL.
# If ID is provided, assign it to a variable.
# If no ID is provided, display an error in the browser.
if 'movieId' in request.args:
movieId = int(request.args['movieId'])
else:
return "Error: No movieId field provided. Please specify an movieId."
if 'imdbId' in request.args:
imdbId = int(request.args['imdbId'])
else:
return "Error: No imdbId field provided. Please specify an imdbId."
results = get_movies_by_movieId_userId(movieId, imdbId)
return jsonify(results)
app.run()