Created
April 23, 2021 09:49
-
-
Save AbhiAgarwal192/2babf467fe27940fd8f825fae1ac7a4e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from flask import Flask | |
from flask import json as flaskjson | |
import json | |
import os | |
app = Flask(__name__) | |
@app.route('/healthcheck', methods=['GET']) | |
def health_check(): | |
return 'Congratulations! The app is running.' | |
@app.route('/movies', methods=['GET']) | |
def movies(): | |
print('Movies Route Called.') | |
movies_file = open('MoviesData.json') | |
response = app.response_class( | |
response = movies_file, | |
mimetype = 'application/json' | |
) | |
return response | |
@app.route('/movies/<title>', methods=['GET']) | |
def moviesByTitle(title): | |
print('Get Movies By Title Route Called.') | |
movies_file = open('MoviesData.json') | |
movies = json.load(movies_file) | |
res_movie = [] | |
for movie in movies: | |
if movie["Title"].lower() == str(title).lower(): | |
res_movie = movie | |
break | |
response = app.response_class( | |
response = flaskjson.dumps(res_movie), | |
mimetype = 'application/json' | |
) | |
return response | |
if __name__ == "__main__": | |
print("Movies Controller App Started!") | |
port = int(os.getenv("PORT", 8080)) | |
app.run(host='0.0.0.0', port=port) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment