Why we should have data validation checks in every backend application?
How do we know if the data sent by client is what we asked for.
For example:
Assuming MERN tech stack
We need pageSize and pageNumber as query parameters in a URL. By default these parameters should be number but what if client/Frontend does not send number? It could crash our server.
Reasons we should have data validation checks:
- Prevent malicious database commands to reach our database
- Give client exact error why request is failing
- Reduce response time
- Does not crash server
Where to put validation check?
We should place validation check right after we receive request. I will tell you in order
1. Validation check
2. Business logic
3. Database call
Need Help? Contact me or Hire me as a Freelancer.
If you have doubts, want career advice, want help with assignment, help at job or anything related to tech.
Connect with me on a video/audio call:
15 mins(Free): https://bit.ly/3rNsoYA
15 mins($7): https://bit.ly/3rJ45Ls
30 mins($49): https://bit.ly/3xgBle4
60 mins($79): https://bit.ly/3zXMwKq
Instagram: https://bit.ly/2V9mgyf
Youtube Channel: https://bit.ly/3zYCzMS
Discord: https://bit.ly/3lp5gyp
Twitter: https://bit.ly/37gdK2J