Showing posts from May, 2024

ASP.NET Core 8: Model Validations in Minimal APIs using Endpoint Filters

Minimal API is the great features of ASP.NET Core. This feature provides a better mechanism to create APIs with less complex code than the traditional controllers' approach. Minimal APIs provides simple and clean code to define HTTP Endpoints. In the case of Minimal APIs, we directly focus on the domain implementation rather than controllers and its actions methods. Minimal APIs offers readability, Testability, as well as they offer an easy approach for building APIs for new professionals.  While implementing APIs, it is important to implement the Model Data Validations to make sure that the data received is valid before it is considered for processing. While using the Minimal APIs, we need to use the Fluent Validations to validate the model data. In this article, we will perform the Model Validation using the FluentValidation package as well as using the Endpoint Filter. The Figure 1 will provide an idea of the Validation in ASP.NET Core Minimal API. Figure 1: The Validation Step