From the course: Building Web APIs with ASP.NET Core 8

Unlock the full course today

Join today to access over 24,700 courses taught by industry experts.

Model validation

Model validation

- [Lecturer] Let's briefly talk about validation now. We've just added the required attribute to the category ID, and I mentioned that that means that we have to set that category ID. There are other attributes apart from required as well, but that's beyond the scope of this course. That's something baked into ASP.NET Core. However required is pretty useful. So let's make other fields required as well. I would say the skew is something we always need. We always need a name. And I would also argue we always need a description. Well, actually we would also need a price most of the time, but let's just use those three things and then let's see what that means to our current API call. Back in postman, let's switch over to posts and let's have a look at our request body. We have the skew, we have the name, but we don't have a description. So when I hit send, what happens? Bad request. But there's more. Let's have a look at the data coming back. One of our validation errors occurred. Okay…

Contents