Validation
Learn how to use schemas for type-safety and payload validation
Intro
We use valibot schemas to validate the request and response payloads. We also publish these schemas via npm at @molin.ai/api so you can use them to validate the response payloads in your code. Using the @molin.ai/api package is optional as long as your implementation is compliant and follows the schemas of each API.
Required fields
Unless a field is marked as optional using v.optional()
, it is required and cannot be null
or undefined
. Generally, all top-level fields are required, nested fields may be optional, and you may provide additional data in the extra
field.
Example
Install our npm package, including valibot
because it is a required peer dependency:
Then, whenever your server receives a request from our API, make sure you run your response through the validator: