Created
October 2, 2012 18:12
-
-
Save corbinbs/3821919 to your computer and use it in GitHub Desktop.
Flask JSON Required Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@app.route("/do/something", methods=['POST']) | |
@json_required( | |
required_fields={ | |
'first_name':"Please enter your first name.", | |
'last_name':"Please enter your last name.", | |
'email':'Please specify a valid email address', | |
'date_of_birth':'Please enter your date of birth' | |
}, | |
validations=[ | |
('email', 'Please specify a valid email address', lambda email: email is not None and EMAIL_REGEX.match(email)), | |
('email', "This email is already in use. Please try a different email address.", verify_account_available), | |
('date_of_birth', 'Please enter a valid date of birth', valid_date_of_birth) | |
] | |
) | |
def do_something_useful(): | |
#Confidently use the data in request.json... | |
return jsonify(status='OK') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment