Mastering Resource Creation and Validation
In this chapter, we will explore creating, validating, and updating data in a web API. We will cover POST
, PUT
, and PATCH
operations, uncovering the critical concepts of model validation and model binding – essential features of ASP.NET Core. Additionally, we will explore Scalar, a new and user-friendly option for an interactive OpenAPI UI. This will allow us to move beyond Swagger UI, which is no longer included as the default tool for generating OpenAPI documentation.
We will focus on the best practice of validating inputs added to our database. To do this, we will use model validation and model binding, which together form the model state – a dictionary containing both the state of the model and the validation results.
The following are the recipes we’re going to cover in this chapter:
- Model validation with data annotations
- Creating a custom validation attribute
- Implementing complex validation...