@rewritetoday/zod provides official Zod schemas for the Rewrite API so you can validate requests, responses, reusable resources, and webhook payloads at runtime.
Repository: github.com/RewriteToday/zod
When to use it
- You want runtime validation in addition to TypeScript types.
- You receive external input before calling Rewrite endpoints.
- You need to validate webhook payloads before handling them.
- You want versioned schemas that stay aligned with Rewrite API models.
Key capabilities
Versioned schemas
Import schemas from namespaces such as
@rewritetoday/zod/v1.REST contracts
Validate endpoint-specific bodies and responses with
REST<Method>* schemas.Reusable API models
Parse shared
API* resources independently from a single endpoint.Webhook safety
Use
WebhookEvent.safeParse(...) to guard webhook handling at the boundary.Install
Request validation example
Webhook validation example
Best practices
Validate at the edges
Validate at the edges
Parse external input before it reaches your business logic so invalid payloads fail fast and predictably.
Keep versions explicit
Keep versions explicit
Import from a specific API namespace such as
@rewritetoday/zod/v1 so upgrades stay deliberate.Pair runtime and transport layers
Pair runtime and transport layers
Combine
@rewritetoday/zod with @rewritetoday/rest and @rewritetoday/types for validation, routing, and transport in one stack.Related docs
Types library
Shared contracts and route builders that complement runtime validation.
REST library
Low-level transport client for sending the payloads you validate with Zod.