-
Book Overview & Buying
-
Table Of Contents
-
Feedback & Rating
Node.js Cookbook - Fifth Edition
By :
In the Implementing the business logic recipe, we stored input data from the POST /recipes endpoint in the database. However, we did not implement any validation logic, which means we could potentially insert a string into the price field or a recipe without name. Furthermore, it’s important to consider security concerns, as a malicious user could potentially insert a recipe with a description that’s excessively large, posing a risk to your application’s performance and storage.
In the backend world, there is a rule: never trust the user’s input. Fastify knows it well, so it integrates a powerful and feature-complete validation process. Let’s see it in action.
Follow these steps to integrate the validation process:
schema property to the POST /recipes route option: const jsonSchemaBody = {
type: 'object',
required...