yupify

be fast, be type-safe


Keywords
fastify, yup, validation, backend
License
MIT
Install
npm install yupify@0.0.5

Documentation

cover

yupify - be fast, be type-safe

In fact, it's just a plugin for fastify that combinig validation schema declaration and typing for any request. No more, no less

Before

fastify.post<{ Querystring: { hello: string } }>(
  "/",
  { schema: { querystring: { hello: string } } },
  ({ query: { hello } }) => {
    return hello;
  }
);

After

yupify.post(
  "/",
  { [Yupify.Query]: yup.object({ hello: yup.string() }) },
  ({ query: { hello } }) => {
    return hello;
  }
);

When to use it

  • You want pretty-damn easy solution to add schema validation to your fastify app
  • You don't want to add messy generics to your codebase

When NOT to use it

  • You need to have maximum control over the server (#todo)

Small docs

How to use it

  1. Register the plugin
const server = fastify();
server.register(yupifyPlugin);
  1. Create Yupify instance
const yupify = createYupify(server);
  1. Use it at your own
yupify.get(
  "/hello",
  {
    [Yupify.Query]: yup.object({
      echo: yup.string(),
    }),
  },
  ({ query: { echo } }) => echo
);

Available "chunks"

Yupify.Body, Yupify.Query, Yupify.Params, Yupify.Headers, Yupify.Response

Available methods

yupify.get, yupify.head, yupify.post, yupify.put, yupify.delete, yupify.options, yupify.patch