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

@routegraph/client

v1.0.0

Published

Type-safe fetch client generated from your RouteGraph routes, no codegen step.

Readme

@routegraph/client

A type-safe fetch client for RouteGraph APIs — types come from a generated RouteMap type, not from a runtime schema registry. No response validation at runtime; the type contract is compile-time only.

Installation

pnpm add @routegraph/client

No peer dependencies — @routegraph/core is referenced for types only, never imported at runtime.

createClient<TRouteMap>(options)

function createClient<TRouteMap extends RouteMap>(options: ClientOptions): ClientProxy<TRouteMap>
interface ClientOptions {
  baseUrl: string
  headers?: Record<string, string>
  fetch?: typeof fetch        // inject a custom fetch, e.g. for testing
  onError?: (err: ClientError) => void
  timeout?: number             // ms; default 30000, applied via AbortSignal.timeout()
}

createClient returns a nested Proxy: api['/users/:id'].GET(args) resolves through two get traps into callRoute(options, 'GET', '/users/:id', args) — no per-route code is generated ahead of time.

ClientResponse<T>

interface ClientResponse<T> {
  data: T
  status: number
  headers: Record<string, string>
  ok: boolean
  raw: Response   // the underlying fetch Response
}

ClientError

Thrown (and passed to options.onError first) on any non-2xx response:

class ClientError extends Error {
  status: number
  body: unknown              // the parsed response body
  request: { method: string; url: string }
}

Usage

import { createClient } from '@routegraph/client'
import type { AppRouteMap } from './routemap.js'   // generated by `routegraph generate-client`

const api = createClient<AppRouteMap>({
  baseUrl: 'http://localhost:3000/api',
  headers: { 'x-demo': 'true' },
  onError: (err) => console.error('[client]', err.status, err.body),
})

const users = await api['/users'].GET({ query: { role: 'admin' } })
console.log(users.data)   // typed from the route's response schema

const created = await api['/users'].POST({ body: { name: 'Ada', email: '[email protected]' } })
//                                                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
//                                                  TS error if the route's body schema requires
//                                                  a field this object is missing

const user = await api['/users/:id'].GET({ params: { id: created.data.id } })

How to use with generate-client

routegraph generate-client --dir ./routes --out ./routemap.ts

This writes a routemap.ts containing only the AppRouteMap type (no runtime code) — built by walking your loaded routes and rendering each one's Zod request/response schemas into a TypeScript type string. Re-run it whenever your routes change (or use --watch); AppRouteMap is what you pass to createClient<AppRouteMap>(). There is no codegen step for the client's runtime behavior itself — createClient's Proxy-based dispatch is a normal, hand-written, published implementation that works for any RouteMap-shaped type you give it.

callRoute() for manual use

import { callRoute } from '@routegraph/client'

const res = await callRoute<{ status: 'ok' }>(
  { baseUrl: 'http://localhost:3000/api' },
  'GET',
  '/health'
)

Useful if you want the URL-building/error-handling behavior without the Proxy ergonomics, or need to call a route not present in your RouteMap.

How AbortSignal/timeout works

If you don't pass args.signal, callRoute builds one via AbortSignal.timeout(options.timeout ?? 30000) — the request aborts automatically after that many milliseconds. Pass your own signal in RequestArgs to control cancellation yourself (the injected timeout signal is only used as a fallback, not combined with a custom one).