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

serverless-api-gateway-request-validator

v1.0.4

Published

Serverless Framework plugin to configure API Gateway request validators

Downloads

6

Readme

Serverless API Gateway Request Validator

A Serverless Framework plugin that adds request validation to your AWS API Gateway endpoints.

Installation

# Using npm
npm install --save-dev serverless-api-gateway-request-validator

# Using Serverless plugin install
serverless plugin install -n serverless-api-gateway-request-validator

Then add the plugin to your serverless.yml file:

plugins:
  - serverless-api-gateway-request-validator

Usage

Add request validation to your functions in serverless.yml:

functions:
  myFunction:
    handler: handler.myFunction
    events:
      - http:
          path: /my-path
          method: post
          request:
            validator:
              type: ALL # Options: BODY_ONLY, PARAMS_ONLY, ALL
            schemas:
              application/json: ${file(schemas/my-schema.json)}
            # Optional: Parameter validation configuration
            parameters:
              paths:
                paramName: true  # Required path parameter
              querystrings:
                queryName: false # Optional query parameter
              headers:
                headerName: true # Required header

Available Validator Types

  • BODY_ONLY: Validates only the request body
  • PARAMS_ONLY: Validates only the request parameters (path, query, header)
  • ALL: Validates both body and parameters

Parameter Validation

You can specify three types of parameters to validate:

  1. Path Parameters: Parameters that are part of the URL path (e.g., /users/{id})
  2. Query Parameters: Parameters that are part of the URL query string (e.g., /users?page=1&limit=10)
  3. Header Parameters: Parameters that are part of the HTTP headers

For each parameter, you can specify whether it is required (true) or optional (false).

Example Configurations

Basic JSON Schema Validation

functions:
  createUser:
    handler: handlers/users.create
    events:
      - http:
          path: /users
          method: post
          request:
            validator:
              type: ALL
            schemas:
              application/json: ${file(schemas/create-user.json)}

Path Parameter Validation

functions:
  getUser:
    handler: handlers/users.get
    events:
      - http:
          path: /users/{id}
          method: get
          request:
            validator:
              type: PARAMS_ONLY
            parameters:
              paths:
                id: true  # Required path parameter

Query Parameter Validation

functions:
  listUsers:
    handler: handlers/users.list
    events:
      - http:
          path: /users
          method: get
          request:
            validator:
              type: PARAMS_ONLY
            parameters:
              querystrings:
                page: false  # Optional query parameter
                limit: false # Optional query parameter
                sort: false  # Optional query parameter

Complete Example

service: my-service

provider:
  name: aws
  runtime: nodejs18.x
  region: us-east-1

plugins:
  - serverless-api-gateway-request-validator

functions:
  createUser:
    handler: handlers/users.create
    events:
      - http:
          path: /users
          method: post
          request:
            validator:
              type: ALL
            schemas:
              application/json: ${file(schemas/create-user.json)}
              
  updateUser:
    handler: handlers/users.update
    events:
      - http:
          path: /users/{id}
          method: put
          request:
            validator:
              type: ALL
            schemas:
              application/json: ${file(schemas/update-user.json)}
            parameters:
              paths:
                id: true
              headers:
                Authorization: true

JSON Schema Example

{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "type": "object",
  "required": ["name", "email"],
  "properties": {
    "name": {
      "type": "string",
      "minLength": 1
    },
    "email": {
      "type": "string",
      "format": "email"
    },
    "age": {
      "type": "integer",
      "minimum": 18
    },
    "address": {
      "type": "object",
      "properties": {
        "street": { "type": "string" },
        "city": { "type": "string" },
        "zipCode": { "type": "string" }
      }
    }
  }
}

How It Works

This plugin works by:

  1. Analyzing your Serverless configuration during the packaging phase
  2. Finding any HTTP events with validator configurations
  3. Creating AWS::ApiGateway::RequestValidator resources in the CloudFormation template
  4. Adding AWS::ApiGateway::Model resources for your JSON schemas
  5. Linking these resources to your API Gateway methods

License

MIT