def people(): country = request.args.get('country') if country is not None: return jsonify( [p for p in json_reader()["people"] if p['country'] == country]) else: return jsonify(json_reader()["people"])
def post_people(): person = request.get_json() person_id = len(json_reader()['people']) data = json_reader() data["people"].append({'id': person_id, **person}) json_writer(data) print(json_reader()) return jsonify({"id": person_id}), 201
def update_person(id): try: data = json_reader() data['people'][id].update(request.get_json()) json_writer(data) return Response(status=204) except IndexError: return Response('Not found', status=404)
def delete_person(id): try: data = json_reader() data['people'][id] = None json_writer(data) return Response(status=204) except IndexError: return Response('Not found', status=404)
def get_person(id): try: return json_reader()['people'][id] except IndexError: return Response('Not found', status=404)
def posts(): data = json_reader()['posts'] return jsonify(data)
def peoples_post(id): data = json_reader()['posts'][id] return data['title']