Checking What Comes In

Checking What Comes In: Checking Input by Hand, Validating with Zod.

Updated

  1. Checking Input by Hand (Apprentice): A server checks every request body before it saves anything, because any program can send anything, and a validation function collects every problem (a missing field, the wrong type, text that's too long, a value that isn't allowed) so the API can answer 400 with the whole list.
  2. Validating with Zod (Journeyman): Zod writes a request body's rules as a schema, an object that describes the shape the data must have, and safeParse checks a body against it, giving back either the cleaned data or a list of issues that the API turns into its field problems.