Join egghead, unlock knowledge.

Want more egghead?

This lesson is for members. Join us? Get access to all 3,000+ tutorials + a community with expert developers around the world.

Unlock This Lesson
1×
Become a member
to unlock all features

Level Up!

Access all courses & lessons on egghead today and lock-in your price for life.

Autoplay

    Add validation rules to a model in LoopBack API

    loopbackLoopback
    ^3.0.0

    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.