liveBook · Manning

Server validation

As explained in Build AI-Enhanced Web Apps

Server validation is input checking performed on a server after client-submitted data arrives and before the data is processed.

Server validation checks submitted input after it reaches the server and before application processing. It remains the source of truth because client-side checks can be bypassed or manipulated. Apply it to every client request, including requests sent to public endpoints. section 9.1.1

A production validation flow should:

  • Treat all client-provided data as tamperable, even when the browser already validates it. section 9.1.1
  • Validate request data before invoking application or model-processing logic. section 9.1.1
  • Use client validation for immediate feedback, but never as the only protection. section 9.1.1

Validate a Next.js API request with Zod

Define a schema requiring a nonempty prompt of no more than 1,000 characters. Parse the request body, process only the validated prompt, and return validation details with status 400 when parsing fails.

How Build AI-Enhanced Web Apps covers it

How deep it goes
Explains the trust boundary, request timing, client-validation contrast, Zod schema, parsing, processing, and error response.
Examples
Demonstrates a Next.js API handler validating a 1,000-character prompt with Zod before processing it.
What it assumes
Assumes client-submitted requests and endpoint processing, while distinguishing browser feedback from server-enforced validation.
What you can do after
Build it from scratch by defining a Zod schema, parsing request data, processing validated values, and returning validation errors.
How it connects
Connects input validation with client validation, public endpoints, security middleware, rate limiting, prompt injection, and API security.

Also explained in

Compare how 3 books explain server validation →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Build AI-Enhanced Web Apps. The section links point to the parts of the book it draws on.