I built a simple user model in Backbone
define([ 'underscore', 'backbone' ], function(_, Backbone) { var UserModel = Backbone.Model.extend({ urlRoot: '/api/user', idAttribute: '_id', defaults: { userName: '', password: '' personalDetails: { title: '', name: { firstName: '', lastName: '' }, gender: '', dob: '' } } }); return UserModel; });
Calling save() on the model will produce a PUT request to /api/user/:id , which will be fine.
However in front I want 3 forms - updatePersonalDetails , updateUserName , updatePassword .
In my current implementation, they will all use the same model and all save() for the same endpoint /api/user/:id . My problem is that I donโt know what form the user posted.
What is the best solution to this problem, although RESTful? Having 3 separate models - UserDetailsModel , UserPasswordModel , etc.? Or just do a voluminous UPDATE on the entire model, no matter what shape it posted.
source share