1. Replace Manual Validation with Zod Schemas

Apply Zod schema validation to your organised restaurants/reviews API from the previous lesson.

  1. Install the zod package.
  2. Create middleware/restaurant-validation.ts with Zod schemas for restaurant data validation.
  3. Create middleware/review-validation.ts with Zod schemas for review data validation.
  4. Replace your existing manual validation middleware with Zod-based versions.

2. Apply Zod Validation to Routes

  1. Update your route files to import from the new Zod validation middleware files.
  2. Test your API with invalid data to see the improved error messages.
  3. Verify all endpoints work correctly with the enhanced validation.

3. Add Advanced Validation Features

Enhance your schemas with additional Zod features:

  1. Add proper number validation for restaurant ratings (1-5 range).
  2. Add string length validation and data transformation (e.g., trim whitespace from restaurant names).
  3. Test comprehensive validation scenarios with various invalid inputs.
Tags: