Back to Loopback Next

Validation

docs/site/Validation.md

4.0.0-alpha.11.4 KB
Original Source

Within a LoopBack application, validation can be added in various places depending on the usage. Some types of validations come out-of-the-box in LoopBack, such as type validation in the REST layer, whereas some require additional configuration or code.

There are various types of validations such as:

  • validation of input/output for method invocations
  • validation of model instance properties, for example, age < 0
  • validation of model collections, for example, uniqueness

Let's take a closer look at how validation can be added in the following layers:

The validation-app example application is used in the following documentation pages for demonstration. In the example, a CoffeeShop model is being used. It has the following properties.

Property nameTypeDescription
shopIdstringID of the coffee shop
citystringCity where the coffee shop is located
phoneNumstringPhone number of the coffee shop
capacitynumberCapacity of the coffee shop