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

@timangames/ts-rest-client

v1.0.1

Published

A tiny HTTP client wrapper for generating TypeScript interfaces for REST endpoints.

Downloads

29

Readme

TypeScript REST Client

A tiny http client wrapper to get a full TypeScript interface for your REST endpoints!

Install

npm TBD

Usage

import {wrap, HttpClient, EntityApi, EntityDef, Entity} from "ts-rest-client";

interface EntityA extends Entity {
    f1: number;
}
interface EntityB extends Entity {
    f2: number;
}
interface EntityC extends Entity {
    f3: number;
}
interface EntityD extends Entity {
    f4: number;
    serverOnlyField: string;
}
interface EntityD extends Entity {
    f5: number;
}


const client = wrap({...} as HttpClient, '/api')
    .createClient<EntityApi<EntityDef<EntityA>, {
                nest1: EntityApi<EntityDef<EntityB>, {
                    nest2: EntityApi<EntityDef<EntityC>, {
                        nest3: EntityApi<EntityDef<EntityD, 'id'|'serverOnlyField'>> // mentioning server-only field that will be excluded from modifications
                    }>
                    nest2_2: EntityApi<EntityDef<EntityE>>,
                }>
            }>
>();


// using the provided HttpClient, the following will send this request:
//  POST /api/id1/nest1,  body: {f2:1}
client.for('id1').nest1.create({f2: 1}).then(e => e.f2);

// using the provided HttpClient, the following will send this request:
//  GET /api/id1/nest1
client.for('id1').nest1.getAll().then(entities => entities.map(e => e.f2));

// using the provided HttpClient, the following will send this request:
//  GET /api/id1/nest1/id2/nest2/id3
client.for('id1').nest1.for('id2').nest2.for('id3').get().then(r => r.f3.toFixed(2));

// using the provided HttpClient, the following will send this request:
//  PUT /api/id1/nest1/id2/nest2/id3, body: {f3: 99}
client.for('id1').nest1.for('id2').nest2.for('id3').update({f3: 99}).then(e => e.f3);

// using the provided HttpClient, the following will send this request:
//  DELETE /api/id1/nest1/id2/nest2/id3
client.for('id1').nest1.for('id2').nest2.for('id3').delete().then(() => console.log(`deleted!`));

EntityDef

type EntityDef<T extends Entity,
    ServerOnlyFields extends keyof T = 'id',
    CreateOnlyFields extends keyof T = ServerOnlyFields
>;
  • T describes the full entity model; must extend Entity<ID_TYPE> that defined the id field.
  • ServerOnlyFields (optional) is a list of fields from T that will be excluded in modifications (create/update)
  • CreateOnlyFields (optional) is a list of fields from T that will excluded only when trying to update and entity (they'll be available when creating).

EntityApi

type EntityApi<
    EDef extends EntityDef,
    SubEntities extends Record<string, EntityApi<any, any, any>> = {},
    SelectedApis extends Partial<AllEntityApi<EDef>> = AllEntityApi<EDef>,
>;
  • EDef see above.
  • SubEntities (optional) sub-entities to a single entity (via get) that will be expose their api.
    • Notice that the name of the sub-entity will part of its path,
  • SelectedApis (optional, default- AllEntityApi) pick which apis to expose for the entity.

HttpClient

export interface HttpClient {
    get: (path: string, query?: object, headers?: Record<string, string>) => Promise<unknown>;
    delete: (path: string, query?: object, headers?: Record<string, string>) => Promise<unknown>;
    put: (path: string, body?: object, query?: object, headers?: Record<string, string>) => Promise<unknown>;
    post: (path: string, body?: object, query?: object, headers?: Record<string, string>) => Promise<unknown>;
}

Is there an HttpClient I can use?

Soon! Until then, feel free to implement the above interface with an adapter [browser/server].

Contributing

Clone the repo, npm i & npm test.