New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

next-yup

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

next-yup

> Simple validation for [Next.js](https://nextjs.org) API routes using [Yup](https://github.com/jquense/yup)

  • 1.1.0
  • latest
  • npm
  • Socket score

Version published
Weekly downloads
3
decreased by-76.92%
Maintainers
1
Weekly downloads
 
Created
Source

next-yup

Simple validation for Next.js API routes using Yup

Install

npm install next-yp
# or
yarn add next-yup

Usage

Get started by creating a Yup object schema and wrapping your API route function with the withYup wrapper:

import withYup from 'next-yup';
import * as yup from 'yup';

export const catSchema = yup.object().shape({
  catName: yup.string().required(),
  isHungry: yup.boolean().required(),
});

export default withYup()({ query: catSchema }, (req, res, data) => {
  // validated data from query parameters, with attempted type cast to match schema
  const { query } = data;
  return res.json({ query });
});

// GET http://localhost:3000/api/query?catName=bob&isHungry=true
// -> { "query": { "isHungry": true, "catName": "bob" } }

FAQs

Package last updated on 09 Mar 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc