Skip to content

Instantly share code, notes, and snippets.

@heymichaelp
Last active August 29, 2015 14:02
Show Gist options
  • Save heymichaelp/c7003193c0bdf40e4232 to your computer and use it in GitHub Desktop.
Save heymichaelp/c7003193c0bdf40e4232 to your computer and use it in GitHub Desktop.
Form Objects: Example of Validator API
// Client-side
var validator = new NewStudentFormValidator().validate(data)
if (validator.isValid()) {
// submit form to server
} else {
// show errors to user
}
// Server-side (application route)
var validator = new NewStudentFormValidator().validate(data)
if (validator.isValid()) {
return new CreateNewStudent(data).run()
// send user to success page
} else {
// send user back to the form page with errors
}
// Server-side (API route)
var validator = new NewStudentFormValidator().validate(data)
if (validator.isValid()) {
return new CreateNewStudent(data).run()
// send 201 with new student JSON
} else {
// send error code
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment