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 🙏

© 2025 – Pkg Stats / Ryan Hefner

hono-helper-toolkit

v1.0.1

Published

A helper package for building scalable APIs with [Hono](https://hono.dev), [Zod](https://zod.dev), and OpenAPI integration, including useful utilities like rate limiting with Redis support.

Readme

hono-helper-toolkit

A helper package for building scalable APIs with Hono, Zod, and OpenAPI integration, including useful utilities like rate limiting with Redis support.


Features

  • Structured route definitions with automatic validation and error handling
  • Easy App generation with OpenAPI documentation
  • Middleware helpers (e.g., rate limiter with in-memory or Redis backend)
  • Ready-to-use patterns for scalable API development

Usage

OpenAPI Factory

Create an OpenAPI documentation and route factory:

import { OpenAPIHonoFactory } from 'hono-helper-toolkit';

const app = OpenAPIHonoFactory({
  title: 'My API',
  description: 'Automatically generated OpenAPI docs',
  contactName: 'Support Team',
  contactEmail: '[email protected]',
  licenseName: 'MIT',
  version: '1.0.0',
  port: 3000,
});

// Add routes using .openapi(routeDefinition, handler)

app.listen(3000);

Rate Limiter Middleware

In-memory or Redis-backed rate limiter middleware:

import { rateLimiter, setRedisClient } from 'hono-helper-toolkit';
import Redis from 'ioredis';

const redisClient = new Redis();

setRedisClient(new Redis({
  host: localhost,
  port: 6397,
  password: 'secret',
}));

app.use(rateLimiter({
  windowMs: 60000,
  maxRequests: 100,
  headerContent: true,
  redisKeyPrefix: 'key'
}));

API

OpenAPIHonoFactory(options)

Creates an instance of OpenAPIHono with default docs configured by options.

  • options.title: string — API title
  • options.description: string — API description
  • options.contactName: string — Contact person name
  • options.contactEmail: string — Contact email
  • options.licenseName: string — License name
  • options.version: string — API version
  • options.port: number — Server port

Returns an OpenAPIHono app instance

rateLimiter(options)

Creates a rate limiting middleware.

  • windowMs: number — Time window in milliseconds
  • maxRequests: number — Max requests per IP in the window
  • headerContent: boolean — Add rate limit headers in responses
  • redisKeyPrefix: string — Redis prefix key for data storage

Returns a middleware function (ctx, next) => Promise

Helper Functions Documentation

executeEndpoint

export const executeEndpoint = async <Response, ErrorResponse>(
  handler: () => Promise<Response>,
  errorHandler: (e: unknown) => ErrorResponse,
): Promise<Response | ErrorResponse>;

A generic utility function to execute asynchronous endpoint logic with error handling.

  • handler — The async function containing the main logic.
  • errorHandler — The function to handle any errors thrown by the handler.

Returns either the successful response or the error response.

executeEndpointWithSchema

export const executeEndpointWithSchema = async <
  Schema extends z.ZodType,
  Response,
  ErrorResponse
>(
  context: Context,
  schema: Schema,
  handler: (value: z.infer<Schema>) => Promise<Response>,
  errorHandler: (e: unknown) => ErrorResponse,
): Promise<Response | ErrorResponse>;

A helper to parse and validate the JSON body of a request against a Zod schema, then execute the handler with the parsed input.

  • context — The Hono context object.
  • schema — A Zod schema to validate and parse the JSON input.
  • handler — Async function receiving the parsed input.
  • errorHandler — Error handling function.

Returns either the successful response or the error response.

ResponseFactory

export type ResponseHelperConfig = {
  defaultOkStatus?: ContentfulStatusCode;
  defaultErrorStatus?: ContentfulStatusCode;
  wrapErrorMessage?: boolean;
  url?: string;
};

export function ResponseFactory(config?: Partial<ResponseHelperConfig>);

Creates a helper object to standardize JSON responses and redirects in endpoints.

Options:

  • defaultOkStatus — HTTP status code for successful responses (default: 200).
  • defaultErrorStatus — HTTP status code for error responses (default: 500).
  • wrapErrorMessage — Wrap error strings in { message: string } object (default: true).
  • url — Default redirect URL (default: './').

Return methods:

  • jsonOk(c: Context, data: JsonCompatible, status?: ContentfulStatusCode) — Respond with JSON success.
  • jsonError(c: Context, message: string | {}, status?: ContentfulStatusCode) — Respond with JSON error.
  • defaultRedirect(c: Context) — Redirect to default URL.
  • redirectTo(c: Context, url: string, status?: RedirectStatusCode) — Redirect to specific URL with status code.

parseJsonInputSchema

export const parseJsonInputSchema = async <T extends z.ZodType>(
  c: Context,
  schema: T
): Promise<z.infer<T>>;

Parses the JSON body of a request and validates it against a Zod schema.

Throws if validation fails.

parseParams

export const parseParams = <T extends z.ZodType>(c: Context, schema: T);

Parses and validates path parameters from the request using a Zod schema.

parseQuery

export const parseQuery = <T extends z.ZodType>(c: Context, schema: T);

Parses and validates query parameters from the request using a Zod schema.