npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@caplab/form-request

v0.3.0

Published

Laravel-inspired request validation for Express. Simple, readable, and developer-friendly.

Readme

Form Request

Laravel-inspired request validation for Express.

Simple, clean, and developer-friendly validation with automatic 422 responses and validated data extraction.

npm version License: MIT


Installation

npm install @caplab/form-request

Quick Example

import express from "express";
import { validation } from "@caplab/form-request";

const app = express();

app.use(express.json());
app.use(validation());

app.post("/register", async (req, res) => {
	await req.validate({
		email: "required|email",
		password: "required|min:6",
	});

	const data = req.validated();

	res.json({
		success: true,
		data,
	});
});

Why Form Request?

Validation in Express is often verbose or fragmented across middleware.

Form Request brings a Laravel-style validation experience to Express:

  • Laravel-like validation syntax
  • Automatic 422 JSON responses
  • Clean validated data extraction
  • Removes unvalidated fields automatically
  • Inline validation or class-based requests
  • Works with both JavaScript and TypeScript

Features

  • Pipe-style validation rules
'email': 'required|email|min:5'
  • Automatic validation error responses
  • req.validated() returns only validated fields
  • Nested object validation
  • Array wildcard validation
  • Custom validation rules
  • Custom error messages
  • TypeScript support
  • FormRequest classes

Basic Usage

Inline Validation

app.post("/login", async (req, res) => {
	const data = await req.validate({
		email: "required|email",
		password: "required|min:6",
	});

	res.json(data);
});

FormRequest Classes

import { FormRequest } from "@caplab/form-request";

class RegisterRequest extends FormRequest {
	rules() {
		return {
			email: "required|email",
			password: "required|min:6",
		};
	}

	messages() {
		return {
			"email.required": "Email is required",
			"email.email": "Email must be valid",
		};
	}
}

app.post("/register", async (req, res) => {
	await req.validate(RegisterRequest);

	const data = req.validated();

	res.json(data);
});

Validated Data Only

Extra fields are automatically removed.

Request body:

{
	"email": "[email protected]",
	"password": "123456",
	"is_admin": true
}

Validated result:

const data = req.validated();

Output:

{
	"email": "[email protected]",
	"password": "123456"
}

Nested Validation

await req.validate({
	"user.email": "required|email",
	"user.name": "required",
	"users.*.email": "required|email",
});

Custom Rules

import { extend } from "@caplab/form-request";

extend("phone", async (value) => {
	return /^\d{10}$/.test(value);
});

await req.validate({
	phone: "required|phone",
});

Custom Messages

await req.validate(
	{
		email: "required|email",
	},
	{
		attributes: {
			email: "email address",
		},
	},
);

Response:

{
	"message": "The email address field is required."
}

Available Rules

| Rule | Description | | ------------ | ------------------------------- | | required | Field is required | | nullable | Field may be null | | string | Must be a string | | number | Must be a number | | integer | Must be an integer | | boolean | Must be a boolean | | array | Must be an array | | object | Must be an object | | email | Must be a valid email | | min:n | Minimum value or length | | max:n | Maximum value or length | | same:field | Must match another field | | confirmed | Requires {field}_confirmation |


Example Validation Error

{
	"message": "The given data was invalid.",
	"errors": {
		"email": ["The email field is required."]
	}
}

License

MIT