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

lessttp

v0.4.0

Published

Tiny tooling for headless HTTP-based lambda functions

Downloads

17

Readme

version MIT License downloads

Installation

npm install lessttp

Usage

Basic

Minimum viable async setup for Netlify Functions with built-in:

  • Content-Type=application/json when you return a JSON object in the body
  • 200 success status when there are no errors
  • Error handling
  • Parses deeply nested query string objects as JSON
  • Validates that GET HTTP method is used
const http = require('lessttp')
const StarWars = require('./services/StarWars')

exports.handler = http.function(async (request) => {
  const allJedi = await StarWars.queryJedi()
  return {
    body: allJedi,
  }
})

Custom error handling

const http = require('lessttp')
const StarWars = require('./services/StarWars')

exports.handler = http.function(async (request) => {
  try {
    const allJedi = await StarWars.queryJedi()
    return {
      body: allJedi,
    }
  } catch (error) {
    console.error(error)
    return {
      statusCode: 502,
      body: 'You were the chosen one!',
    }
  }
})

Custom path parameters

const http = require('lessttp')
const StarWars = require('./services/StarWars')
const baseUrl = '/.netlify/functions'

exports.handler = http.function({
  path: `${baseUrl}/jedi/:id`,
  async handler(request) {
    const { id } = request.params
    const jedi = await (id ? StarWars.getJediById(id) : StarWars.queryJedi())
    return {
      body: jedi,
    }
  },
})

Parsing deeply nested query objects

While the request query string is already parsed as JSON, the built-in middleware further uses qs.parse which supports deeply nested objects.

const http = require('lessttp')
const StarWars = require('./services/StarWars')
const baseUrl = '/.netlify/functions'

exports.handler = http.function({
  path: `${baseUrl}/jedi`,
  async handler(request) {
    const { id, filter: { name, side } } = request.query
    const jedi = await (id ? StarWars.getJediById(id) : StarWars.queryJedi({ name, side }))
    return {
      body: jedi,
    }
  },
})

Custom HTTP method

The request body is automatically parsed as JSON when available:

const http = require('lessttp')
const StarWars = require('./services/StarWars')

exports.handler = http.function({
  method: 'POST',
  async handler(request) {
    const jedi = await StarWars.createJedi(request.body)
    return {
      body: jedi,
    }
  }
})

Custom request validation

Validate request body, headers, params, or query using powerful JSON schemas:

const http = require('lessttp')
const StarWars = require('./services/StarWars')

exports.handler = http.function({
  method: 'POST',
  request: {
    body: {
      type: 'object',
      properties: {
        name: { type: 'string' },
        side: { type: 'string', enum: ['light', 'neutral', 'dark'] },
      },
      required: ['name', 'side'],
      additionalProperties: false,
    }
  },
  async handler(request) {
    const jedi = await StarWars.createJedi(request.body)
    return {
      body: jedi,
    }
  }
})

RESTful paths

Easily combine multiple handlers to create REST endpoints:

const http = require('lessttp')
const StarWars = require('./services/StarWars')

exports.handler = http.resource({
  async get() {
    const allJedi = await StarWars.queryJedi()
    return {
      body: allJedi,
    }
  },
  post: {
    request: {
      body: {
        type: 'object',
        properties: {
          name: { type: 'string' },
          side: { type: 'string', enum: ['light', 'neutral', 'dark'] },
        },
        required: ['name', 'side'],
        additionalProperties: false,
      }
    },
    async handler(request) {
      const jedi = await StarWars.createJedi(request.body)
      return {
        body: jedi,
      }
    },
  },
})

Override individual middleware functions

You can override individual functions by key:

const http = require('lessttp')
const StarWars = require('./services/StarWars')

exports.handler = http.function({
  middleware: {
    async parseBody(request) {
      if (request.body) {
        try {
          request.body = JSON.parse(request.body)
        } catch (error) {
          return {
            statusCode: 400,
            body: 'You were supposed to bring balance to the Force!'
          }
        }
      }
    }
  },
  async handler(request) {
    const jedi = await StarWars.createJedi(request.body)
    return {
      body: jedi,
    }
  }
})

Override all middleware

Replace the middleware array entirely:

const http = require('lessttp')
const { alias, validateHttpMethod } = require('lessttp/middleware')
const StarWars = require('./services/StarWars')

exports.handler = http.function({
  method: 'POST',
  middleware() {
    return [
      alias({ httpMethod: 'method', queryStringParameters: 'query' }),
      validateHttpMethod(this.method),
      async function parseBody(request) {
        if (request.body) {
          try {
            request.body = JSON.parse(request.body)
          } catch (error) {
            return {
              statusCode: 400,
              body: 'You were supposed to bring balance to the Force!'
            }
          }
        }
      }
    ]
  },
  async handler(request) {
    const jedi = await StarWars.createJedi(request.body)
    return {
      body: jedi,
    }
  }
})

Disable middleware

Disable the middleware completely and do everything yourself in the handler:

const http = require('lessttp')
const StarWars = require('./services/StarWars')

exports.handler = http.function({
  method: 'POST',
  middleware: null,
  async handler(request) {
    let body
    try {
      body = JSON.parse(request.body)
    } catch (error) {
      console.error(error)
      return {
        statusCode: 400,
        body: 'You were supposed to bring balance to the Force!'
      }
    }

    try {
      const jedi = await StarWars.createJedi(body)
      return {
        body: jedi,
      }
    } catch (error) {
      console.error(error)
      return {
        statusCode: 502,
        body: 'You were the chosen one!',
      }
    }
  }
})