API input coercion for query params (Zod preprocess)

397
0

Query params arrive as strings, and ad-hoc parsing logic tends to drift across endpoints. I use Zod preprocessors to coerce values like page size and booleans, then validate the result. This keeps the handler readable and makes parsing rules shareable between routes. I also clamp values to sane ranges so a client can’t ask for 10_000 items per page and accidentally DoS the system. The practical benefit is fewer weird undefined edge cases on the backend and fewer defensive checks on the frontend. When parsing rules live in one place, they’re easier to test and harder to forget.