Validation
It is a best practice to validate the incoming properties on your endpoint before executing the associated method. This not only increases the performance of the API, but it also protects you from some forms of hacking (for example, injection).
Our recommendation is to use the FluentValidation
NuGet package, which you can install as shown in the Technical requirements section at the start of this chapter.
Once installed, you have many options as to how to capture errors. Let’s look at a few.