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
From the course: Building Web APIs with ASP.NET Core 8
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…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
(Locked)
HTTP methods3m 8s
-
(Locked)
Model binding4m 31s
-
(Locked)
Adding an item with POST12m 14s
-
(Locked)
Model validation5m
-
(Locked)
Updating an item with PUT7m 59s
-
(Locked)
Deleting an item with DELETE4m 45s
-
(Locked)
Migrating the code to Minimal APIs6m 21s
-
(Locked)
Challenge: Deleting several items41s
-
(Locked)
Solution: Deleting several items5m 40s
-
(Locked)
-