Skip to content

Commit

Permalink
docs: add valibot usage
Browse files Browse the repository at this point in the history
  • Loading branch information
jellydn committed Oct 14, 2023
1 parent 48f6623 commit 7617097
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,36 @@ const handler = (req: NextApiRequest, res: NextApiResponse) => {
export default validate(handler);
```


### Validate custom API endpoint with Valibot

```sh
yarn add valibot next-validations
```

```typescript
import { NextApiRequest, NextApiResponse } from 'next';
import { withValidation } from 'next-validations';
import * as valibot from 'valibot';

const schema = valibot.object({
name: valibot.string([valibot.minLength(4)]),
});

const validate = withValidation({
schema,
type: 'Valibot',
mode: 'query',
});

const handler = (req: NextApiRequest, res: NextApiResponse) => {
res.status(200).json(req.query);
};

export default validate(handler)
```


### Validate custom API endpoint with fastest-validator

```sh
Expand Down

0 comments on commit 7617097

Please sign in to comment.