Imagine that this is the object sent from the frontend to the backend:Ĭonst express = require ( " express " ) const Joi = require ( " joi " ) const app = express () app. Basically Joi provides methods to easily validate strings, booleans, integers, email addresses, phone numbers, among others. Joi is a validation library that allows you to build schemas to validate JavaScript objects. In this way, no operation is performed that is sensitive in our application, nor do we have any interaction with external resources (such as caching, database, etc). In the example of this article we will create middleware that will validate the data before reaching the controller (where the application logic is supposed to be). Basically, when using a validation library, it is easier to validate the data before accessing the database. I believe that a lot of people must be asking why we will use a validation library since many ORMs let us create restrictions for their schemes and models. The library in question is called Joi, in my opinion it is the easiest validation library to implement, it is super popular and there are still several ways to implement it. But in this article I will talk about a library that can be used in the backend. From what I usually see on the internet, most people implement form validation just on the client side. This standardization can be from the type of data, up to the number of characters.ĭata validation can be done on the client side and on the server side. And as soon as the data is valid, we know that it is safe, because we define a set of rules to be followed, in order to have a standardization. ![]() The generated schema can be tested immediately via a form that is driven by it. ![]() Web forms have become an essential part of web applications. Altova XMLSpy 2019r3 - Graphical JSON Schema editor for draft-06 and draft-7, as well as validation of JSON files based on JSON Schema Dashjoin JSON Schema editor - Graphical online JSON Schema editor for draft-06 (minus oneOf, anyOf, allOf, not).
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |