Skip to content

Instantly share code, notes, and snippets.

@cktricky
Last active January 2, 2016 15:59
Show Gist options
  • Save cktricky/8326865 to your computer and use it in GitHub Desktop.
Save cktricky/8326865 to your computer and use it in GitHub Desktop.
mass-assignment

##Client Request##

The following is a post request sent by a user during the registration process

POST /api/create_user HTTP/1.1
Accept: application/json
Content-Type: application/json;charset=UTF-8
Host: localhost
Connection: Keep-Alive
Accept-Encoding: gzip
Content-Length: 2103

first_name=Ken&last_name=Johnson&password=lolcats&password_confirmation=lolcats&email=test@test.com

##Web Application##

The following code is used by the application to process the new user's request. The application code takes the body of the POST request req.body and instantiates a new user model object new User() with them. Any parameters submitted by the user are converted into database attributes and values.

var user = new User(req.body);
user.save();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment