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-trail

v1.0.0

Published

A generic REST API client that can be easily typed with TypeScript

Readme

TypedTrail

A generic REST API client that can be easily typed with TypeScript

When fetching a REST API, one of the pain points for client is having to deal with types.

TypedTrail is here to make it easier:

import TypedTrail, { DefineApiRoutes } from "typed-trail";

// Defining some objects handled by our hypothetical API
interface User {
  id: number;
  name: string;
  email: string;
}

interface Book {
  id: number;
  title: string;
  authorId: User["id"];
}

// Define all the routes of our hypothetical API.
// Note the usage of DefineApiRoutes: it's an utility type enabling
// TypeScript autocompletion when defining your API routes.
type ApiRoutes = DefineApiRoutes<{
  "/users": {
    // Only GET method is authorized on /users
    GET: {
      // Allowed query params on this route (?name=x&email=x&page=x)
      queryParams: { name: string; email: string; page: number };
      // This route returns an array of users
      response: User[];
    };
  };
  "/users/:userId": {
    // Only GET method is authorized on /users/:userId
    GET: {
      // Route param are parameters directly in the URL
      routeParams: { userId: number };
      // This route of course returns a single user
      response: User;
    };
  };
  "/users/:userId/books": {
    // We can get the list of books from a specific user
    GET: {
      routeParams: { userId: number };
      queryParams: { title: string };
      response: Book[];
    };
    // We can also create a new book for a specific user
    POST: {
      routeParams: { userId: number };
      body: Pick<Book, "title">;
      response: Book;
    };
  };
}>;

// Create a new client API by providing defined routes
const client = new TypedTrail<ApiRoutes>("https://www.contoso.com/api");

client
  // createGetRequest only accepts as parameter routes with GET key defined
  .createGetRequest("/users/:userId")
  // setRouteParam only accepts properties defined via prop "routeParams" of corresponding route
  .setRouteParam("userId", 123)
  // execute fetch the request and returns a Promise with the response of the API
  .execute()
  .then(({ body }) => {
    console.log(body.id); // The response body is correctly typed as User
  });

client
  // createPostRequest only accepts as parameter routes with POST key defined
  .createPostRequest("/users/:userId/books")
  // setRouteParam only accepts properties defined via prop "routeParams" of corresponding route
  .setRouteParam("userId", 123)
  // setBody only accepts properties defined via prop "body" of corresponding route
  .setBody({
    title: "Jurassic Park",
  })
  // execute fetch the request and returns a Promise with the response of the API
  .execute()
  .then(({ body }) => {
    console.log(body.id); // The response body is correctly typed as Book
  });