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

typed-route-client

v0.1.1

Published

Typed REST routes with Zod and optional TanStack Query hooks for React

Downloads

322

Readme

typed-route-client

Biblioteca TypeScript para APIs REST com rotas tipadas + Zod, transporte HTTP plugável e hooks React opcionais (TanStack Query v5).

A lib não inclui adapter HTTP (fetch, axios, etc.). Você implementa HttpTransport no app.


Instalação

npm (em breve)

pnpm add typed-route-client

Dependências (peers)

| Subpath | Instalar no app | | -------- | --------------------------------------------------- | | /core | zod | | /react | zod, react (>=18), @tanstack/react-query (^5) |


Entry points

| Import | Uso | | -------------------------- | ------------------------------------------------ | | typed-route-client/core | Headless: rotas, cliente, validação Zod | | typed-route-client/react | Hooks useApiQuery / useApiMutation + atalhos |

Não há export na raiz do pacote — escolha /core ou /react explicitamente.


Core (sem React)

import {
  defineApiRoutes,
  createRouteClient,
  type HttpTransport,
  type HttpTransportRequest,
  type HttpTransportResponse,
} from 'typed-route-client/core';
import { z } from 'zod';

const routes = defineApiRoutes({
  '/users': {
    methods: {
      get: {
        responseSchema: z.array(z.object({ id: z.number(), name: z.string() })),
      },
    },
  },
});

const transport: HttpTransport = {
  async request(req: HttpTransportRequest): Promise<HttpTransportResponse> {
    const res = await fetch(req.url, {
      method: req.method,
      headers: req.headers,
      body: req.body,
    });
    return {
      status: res.status,
      data: await res.json(),
    };
  },
};

const client = createRouteClient({ routes, transport });

const users = await client.callRoute('/users');

React + TanStack Query

import { defineApiRoutes } from 'typed-route-client/core';
import { createApiClient } from 'typed-route-client/react';
import { z } from 'zod';

const routes = defineApiRoutes({
  '/users': {
    methods: {
      get: {
        responseSchema: z.array(z.object({ id: z.number(), name: z.string() })),
      },
    },
  },
});

const { useApiQuery, useApiMutation } = createApiClient({
  routes,
  transport: myTransport,
});

function UserList() {
  const { data, isLoading } = useApiQuery('/users');
  // ...
}

Alternativa com factories separadas:

import { createRouteClient } from 'typed-route-client/core';
import { createReactQueryHooks } from 'typed-route-client/react';

const routeClient = createRouteClient({ routes, transport });
const { useApiQuery, useApiMutation } = createReactQueryHooks(routeClient);

API principal

Core (typed-route-client/core)

| Export | Descrição | | ------------------------------------------------------ | -------------------------------------------- | | defineApiRoutes, mergeApiRoutes | Contrato de rotas com literais de path | | createRouteClient | Cliente tipado (callRoute, runCallRoute) | | runCallRoute, executeCallRoute | Chamadas com método explícito | | HttpTransport, HttpTransportError | Contrato de transporte | | parseRoute, areRouteParamsReady, resolveApiError | Utilitários |

React (typed-route-client/react)

| Export | Descrição | | ------------------------- | -------------------------------------------- | | createApiClient | routeClient + hooks tipados | | createReactQueryHooks | Hooks a partir de um routeClient existente | | createUseApiQuery | Factory de hook de query | | createUseApiMutation | Factory de hook de mutation | | RouteRegistryFromClient | Extrai o registry de typeof routeClient |


Desenvolvimento

pnpm install
pnpm test
pnpm run build   # gera dist/ localmente (não versionado no git)
pnpm lint:fix

Release automático no push para main (GitHub Actions): lint, test, build e publicação no npm via semantic-release.


Licença

Ver LICENSE.