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

@gradienttim/hono-versioning

v0.2.0

Published

Type-safe API versioning for Hono - URI, header, query, media type, and subdomain strategies

Readme

@gradienttim/hono-versioning

Type-safe API versioning for Hono, with URI, header, query, media type and subdomain strategies.

  • Five strategies: /v1/users, X-API-Version: v1, ?version=v1, Accept: application/vnd.example.v1+json or v1.api.example.com
  • Fully typed: the RPC client (hc) knows every version and its routes
  • Plain Hono apps: each version is a normal Hono instance with its own middleware, onError and notFound
  • Runs anywhere Hono runs: Bun, Deno, Node.js, Cloudflare Workers and other edge runtimes

📖 Documentation

Install

bun add @gradienttim/hono-versioning hono
# or: npm install @gradienttim/hono-versioning hono

Usage

import { Hono } from 'hono'
import { versioning } from '@gradienttim/hono-versioning'

const v1 = new Hono().get('/users', (c) => c.json([{ name: 'Ada' }]))
const v2 = new Hono().get('/users', (c) => c.json({ data: [{ name: 'Ada' }] }))

const app = versioning({
  versions: { v1, v2 },
  defaultVersion: 'v2',
})

// GET /v1/users -> v1
// GET /v2/users -> v2
// GET /users    -> v2 (default version)

export default app

Pick the version from somewhere other than the path:

const versions = { v1, v2 }

versioning({ versions, defaultVersion: 'v2', strategy: { type: 'header' } }) // X-API-Version: v1
versioning({ versions, defaultVersion: 'v2', strategy: { type: 'query' } }) // ?version=v1
versioning({ versions, defaultVersion: 'v2', strategy: { type: 'mediaType', vendor: 'example' } }) // Accept: application/vnd.example.v1+json
versioning({ versions, defaultVersion: 'v2', strategy: { type: 'mediaType', parameter: 'version' } }) // Accept: application/json; version=v1
versioning({ versions, defaultVersion: 'v2', strategy: { type: 'subdomain', baseDomain: 'api.example.com' } }) // v1.api.example.com

These strategies serve every version on the same paths. When no version is sent, the default version answers. The header and media type strategies add Vary: X-API-Version or Vary: Accept so caches keep one response per version. The media type strategy reads Accept lists with q weights, e.g. application/json, application/vnd.example.v1+json;q=0.9.

The typed client follows the strategy: with mediaType it requires an Accept header for a registered version, with subdomain the version comes from the client's base URL (hc('http://v1.api.example.com')).

Custom header and query names, error handling, disabling the default version, proxies (trustForwardedHost) and the typed client are covered in the documentation. Runnable examples are in examples/.

Migration

Your existing app becomes the first version. Routes, middleware, onError and notFound stay as they are; only the top-level app changes.

// Before
const app = new Hono().get('/users', (c) => c.json([{ name: 'Ada' }]))

export default app
// After
const v1 = new Hono().get('/users', (c) => c.json([{ name: 'Ada' }]))

const app = versioning({
  versions: { v1 },
  defaultVersion: 'v1', // existing clients calling /users keep working
})

export default app

Options you passed to new Hono() move to the second argument of versioning(), which creates the top-level app:

// Before
const app = new Hono({ strict: false }).get('/users', (c) => c.json([{ name: 'Ada' }]))
// After
const v1 = new Hono({ strict: false }).get('/users', (c) => c.json([{ name: 'Ada' }]))

const app = versioning(
  { versions: { v1 }, defaultVersion: 'v1' },
  { strict: false } // same options as `new Hono(...)`
)

Keep the options on the version apps too if their own routing depends on them (e.g. strict).

License

MIT