Added POST capability to books endpoint

pull/1/head
androiddrew 7 years ago
parent 107bffa497
commit 50d113dce8

@ -1,4 +1,4 @@
from flask import Flask, jsonify from flask import Flask, jsonify, request
from flask_cors import CORS from flask_cors import CORS
# config # config
@ -37,12 +37,20 @@ def ping_route():
return jsonify('You pass butter') return jsonify('You pass butter')
@app.route('/books', methods=['GET']) @app.route('/books', methods=['GET', 'POST'])
def all_books(): def all_books():
return jsonify({ response_object = {'status': 'success'}
'status': 'success', if request.method == 'POST':
'books': BOOKS post_data = request.get_json()
}) BOOKS.append({
'title': post_data.get('title'),
'author': post_data.get('author'),
'read': post_data.get('read')
})
response_object['message'] = 'Book added!'
else:
response_object['books'] = BOOKS
return jsonify(response_object)
if __name__ == '__main__': if __name__ == '__main__':

Loading…
Cancel
Save