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

@asterflow/router

v2.2.0

Published

Typed route and middleware definitions (Method, Router, Middleware) for AsterFlow applications.

Readme

@asterflow/router

license-info stars-info last-commit

bundle-size

Typed route and middleware definitions (Method, Router, Middleware) for AsterFlow applications.

📦 Installation

bun install @asterflow/router

✨ Features

  • Method - defines a single route bound to one HTTP verb, passed as the first argument (new Method('post', {...}) or Method.POST). Method.create(method) defers the handler so plugins can chain in request extensions (e.g. .multipart({...})) before the terminal .handler(fn) call.
  • Router - groups handlers for several HTTP verbs under one path. Router.builder() gives an extensible, per-method builder (.method('post', b => ...)) so each verb can carry its own request extensions independently.
  • Middleware - typed middleware chain. onRun either calls next(params) to continue (merging params into the typed middleware context) or returns an AsterResponse to short-circuit the chain.
  • Schema validation - route schemas accept a Zod schema or a @caeljs/tsh shape; the parsed result is inferred straight into the handler's schema argument.
  • Extension registry - a WeakMap-based store (extensionRegistry.ts) that plugins use to attach per-router, per-method data, read back at request time.

❓ How to Use

For a normal route, use new Method(method, options) - the HTTP method comes first, either as a plain string or as one of Method's own constants (Method.GET, Method.POST, ...) - and validate the body with Zod:

import { Method } from '@asterflow/router'
import { z } from 'zod'

export default new Method(Method.POST, {
  path: '/users',
  schema: z.object({ name: z.string(), email: z.string().email() }),
  handler({ schema, response }) {
    return response.created({ user: schema })
  }
})

Only reach for Method.create(method, options?) when you need a plugin's fully-typed extension - like multipart's .multipart(schema) - chained in before the handler. create() defers the handler so the extension can widen the request type first, and options is optional:

import { Method } from '@asterflow/router'

export default Method.create(Method.POST)
  .multipart({
    avatar: { mimeTypes: ['image/png', 'image/jpeg'], maxSize: 5 * 1024 * 1024, required: true }
  })
  .handler(({ request, response }) => {
    const avatar = request.getFile('avatar')
    return response.success({ filename: avatar.filename })
  })

Both examples use export default: it's what app.controller(route) expects when you register a route by hand, and it's the export @asterflow/fs's file-based routing looks for in every route file.

🔗 Related Packages

  • asterflow - core framework, depends on this package to register and run routes
  • @asterflow/request - request abstraction; this package imports its Request/AsterRequest types for route and middleware handlers
  • @asterflow/fs - filesystem-based routing plugin, builds routes with Method/Router
  • @asterflow/multipart - multipart upload plugin, extends Method routes

📄 License

This project is licensed under the MIT License.