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
# config
@ -37,12 +37,20 @@ def ping_route():
return jsonify('You pass butter')
@app.route('/books', methods=['GET'])
@app.route('/books', methods=['GET', 'POST'])
def all_books():
return jsonify({
'status': 'success',
'books': BOOKS
response_object = {'status': 'success'}
if request.method == 'POST':
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__':

Loading…
Cancel
Save