javascript-jsonapi-model-library
v0.3.0
Published
Provide base model to deal with jsonapi models
Downloads
6
Keywords
Readme
javascript-jsonapi-model-library
Provide base model to deal with jsonapi models
Installation
$ npm install --save javascript-jsonapi-model-library
Usage
import Model from 'javascript-jsonapi-model-library';
const schema = 'a json-schema';
class Profile extends Model {
constructor(values) {
super(values, schema);
this.setJsonConfig({
attributes: ['name', 'email']
});
}
}
let profile = new Profile({name: 'Simon', email: '[email protected]', state: 'approved'});
assert(profile.get('name') === 'Simon');
try {
profile.validate();
reply(profile.toJson());
} catch (e) {
// deal with error
}