Skip to content

Commit 3a9bb1f

Browse files
committed
- add request/response models and validator to sample code in request validation doc
1 parent fa9f38d commit 3a9bb1f

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

docs/RequestValidation.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,18 @@ You can customize this behavior for individual endpoints by overriding the `Hand
1212
>**Note**: If request validation fails, the endpoint handler method `HandleAsync` will not be called.
1313
1414
```csharp
15+
public record GetBookByIdRequest(Guid Id);
16+
17+
public record GetBookByIdResponse(Guid Id, string Title, string Author, decimal Price);
18+
19+
internal class GetBookByIdRequestValidator : AbstractValidator<GetBookByIdRequest>
20+
{
21+
public GetBookByIdRequestValidator()
22+
{
23+
RuleFor(x => x.Id).NotEmpty();
24+
}
25+
}
26+
1527
internal class GetBookById(ServiceDbContext db)
1628
: WebResultEndpoint<GetBookByIdRequest, GetBookByIdResponse>
1729
{

0 commit comments

Comments
 (0)