I'm trying to write a get request for a list of actors using flask. Here is an example json data object:
{
"age": 61,
"json_class": "Actor",
"name": "Bruce Willis",
"total_gross": 562709189
}
How would I write the flask get request such that '/actors?attr={attr_value}' would filter out such that if it was "actors?name='Bruce'", would give me all actors with the name Bruce.
Something along this line I believe:
@app.route('/actors? (what here)', methods=['GET'])
def actorByAttr(name):
names = [data[string] for string in data if data[string]['json_class'] == 'Actor' and string == name]
if len(names) > 0:
return jsonify(names[0])
else:
return jsonify({'message': "No one found with name: "+ name})
EDIT: Also, how could I incorporate AND and OR operators, such as:
name=”Bruce”|name=”Matt”, name=”Bruce”&age=61