Skip to content

Instantly share code, notes, and snippets.

@5t33
Last active June 29, 2024 18:58
Show Gist options
  • Save 5t33/58844169e2e0587bcbb5b1c6ff1a0fde to your computer and use it in GitHub Desktop.
Save 5t33/58844169e2e0587bcbb5b1c6ff1a0fde to your computer and use it in GitHub Desktop.
validate_book_post
@app.route('/book', methods=['POST'])
def create_book():
data = request.get_json()
if not ("title" in data and "author" in data and "genre" in data):
return {"message": "\"title\", \"author\", and \"genre\" are required fields"}, 400
library[data['title']] = data
return library[data['title']], 201
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment