🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Book a DemoInstallSign in
Socket

koa-zod-middleware

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

koa-zod-middleware

Koa middleware leveraging Zod for seamless validation of requests and responses.

2.0.1
latest
Source
npm
Version published
Weekly downloads
2
-50%
Maintainers
1
Weekly downloads
 
Created
Source

koa-zod-middleware

Koa middleware leveraging Zod for seamless validation of requests and responses.

Usage with @koa/router

import Router from '@koa/router';
import { parse } from 'koa-zod-middleware';
import { z } from 'zod';

const router = new Router();

const schema = {
  query: z.object({
    count: z.coerce.number(),
  }),
  body: z.object({
    fruit: z.string(),
  }),
  response: z.object({
    cart: z.string(),
  }),
};

router.post('/purchase', parse(schema), async (ctx) => {
  const { count } = ctx.request.query;
  const { fruit } = ctx.request.body;

  ctx.status = 200;
  ctx.body = {
    cart: `Purchase ${count} ${fruit}`,
  };
});

Keywords

Zod

FAQs

Package last updated on 31 Jan 2024

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