This Lesson is for PRO Members.

Subscribe today and get access to all lessons! Plus direct HD download
for offline use, member comment forums, and iTunes "podcast" RSS feed.
Level up your skills now!

UNLOCK THIS LESSON

Already subscribed? Sign In

HIDE PLAYLIST

Add validation rules to a model in LoopBack API


We can add validation rules to our models to make sure the data we store in our API is how we want it.

In this lesson we will add validation rules to the Product model.

We will make sure the product name has a minimal length using the validatesLengthOf rule and that it is unique using the validatesUniquenessOf rule.

For the price property we will add a custom validation to make sure that the value entered is not a negative integer. Additionally we will show how to do an async validation using validateAsync . This can for instance be useful if you want the validation to depend on a value in the database or a remote system.

Please take a moment to tell your friends:

You must be a PRO Member to view code