Request Validation
ELI5 — The Vibe Check
Request validation is checking that incoming data makes sense before you do anything with it. Is the email actually an email? Is the age a number and not 'banana'? It's like checking IDs at the door — reject the nonsense before it gets inside.
Real Talk
Request validation verifies that incoming HTTP request data (body, query params, path params, headers) conforms to expected schemas and constraints. It catches malformed data early, prevents injection attacks, and provides clear error messages. Libraries like Joi, Zod, Pydantic, and class-validator automate schema-based validation.
Show Me The Code
import { z } from 'zod';
const CreateUserSchema = z.object({
email: z.string().email(),
age: z.number().min(13).max(120),
name: z.string().min(1).max(100)
});
const data = CreateUserSchema.parse(req.body); // throws if invalid
When You'll Hear This
"Always validate request data — never trust the client." / "Zod catches the invalid email before it reaches the database."
Related Terms
Input Validation
Input validation is checking that user input is what you expect before using it.
Pydantic
Pydantic is Python's strict bouncer at the data nightclub.
Validation
Validation is your backend's bouncer. Before any data gets into the database, the bouncer checks it: 'Is this email actually an email?
Zod
Zod is your runtime bouncer for TypeScript. TypeScript checks types at build time, but Zod checks them when actual data arrives. API response looks weird?