- All Courses
- API Design with Node.js
- Building the Service
- Request validation
Lesson 2.2
Request validation
Every part of a request is user input, including path and query parameters.
5mBeginner17.4k students
Overview
Nothing untrusted goes past the edge
Every part of a request is user input, including path and query parameters. Validate all of them against a schema at the boundary, and let the rest of the code work with a typed, known-good object.
Errors should say which field failed and why. A single "invalid request" message forces the client developer to bisect their payload by hand.
Decide explicitly what happens to unknown fields. Silently ignoring them hides client typos; rejecting them is stricter but can break clients when you later remove a field.
In this lesson you will:
- Validate body, query, and path parameters
- Return field-level errors
- Reject unknown fields deliberately
Resources
Notes are not saved yet — they clear when you leave this page.
Previous Lesson
Routing and middleware
15m
Error handling and problem details
9m