New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

@nextvalid/zod-request

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@nextvalid/zod-request

[![npm](https://img.shields.io/npm/v/@nextvalid/zod-request?style=for-the-badge&labelColor=222)](https://www.npmjs.com/package/@nextvalid/zod-request) [![size](https://img.shields.io/bundlephobia/minzip/@nextvalid/zod-request@latest?label=MinGZIP&style=fo

latest
Source
npmnpm
Version
0.4.0
Version published
Maintainers
1
Created
Source

@nextvalid/zod-request

npm size node dist ci codecov techdebt maintainability license ko-fi

Highlights

  • 🚀  Dead simple

Documentation

Install

npm install @nextvalid/zod-request --save  # via npm
yarn add @nextvalid/zod-request            # via yarn

Quick start

Api routes

Define a schema

import type { NextApiHandler } from "next";
import { zodReq } from "@nextvalid/zod-request";
import { z } from "zod";

const schema = zodReq({
  method: "GET",
  query: {
    email: z.string().email("Invalid email").optional(),
  },
  headers: {
    // authorization: z.string().regex(/^bearer /i),
  },
});

const getHandler: NextApiHandler = async (req, res) => {
  const { query, headers } = schema.parse(req);

  const { email } = query; // email is typed to `string | undefined`
  res.json({
    email: email ? `Your email is ${email}` : `No email provided`,
  });
};

export default withApiErrorHandler({
  logger: new ConsoleLogger(),
})(getHandler);

SSR pages

getServerSideProps, getStaticProps

Support

Open an issue.

Contributors

Contributions are warmly appreciated. Have a look to the CONTRIBUTING document.

Sponsors ♥

If you are enjoying some of my OSS guides or libs for your company, I'd really appreciate a sponsorship, a coffee or a dropped star. That gives me a tasty morning boost and help me to make some of my ideas come true 🙏

License

MIT

Keywords

nextjs

FAQs

Package last updated on 21 Dec 2022

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