1. Replace Manual Validation with Zod Schemas
Apply Zod schema validation to your organised restaurants/reviews API from the previous lesson.
- Install the
zodpackage. - Create
middleware/restaurant-validation.tswith Zod schemas for restaurant data validation. - Create
middleware/review-validation.tswith Zod schemas for review data validation. - Replace your existing manual validation middleware with Zod-based versions.
2. Apply Zod Validation to Routes
- Update your route files to import from the new Zod validation middleware files.
- Test your API with invalid data to see the improved error messages.
- Verify all endpoints work correctly with the enhanced validation.
3. Add Advanced Validation Features
Enhance your schemas with additional Zod features:
- Add proper number validation for restaurant ratings (1-5 range).
- Add string length validation and data transformation (e.g., trim whitespace from restaurant names).
- Test comprehensive validation scenarios with various invalid inputs.