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

@ts-fetcher/rest

v1.4.4

Published

Class and factory based wrapper over fetch API with optional caching (rest module from ts-fetcher)

Readme

ts-fetcher

TypeScript module for convenient fetch API handling

Features

  • [x] Full type safety
  • [x] Minimal boilerplate
  • [x] Class-based approach

Installation

npm install @ts-fetcher/rest
# or
yarn add @ts-fetcher/rest
# or
bun add @ts-fetcher/rest
# or
pnpm add @ts-fetcher/rest

Quick start

  1. Using pre-built classes
import { Rest } from '@ts-fetcher/rest';

const defaultRest = new Rest('https://api.example.com');
  1. Using factories
// Create own class and own factory
import { createRest, createCache } from '@ts-fetcher/rest';

const { CustomRest: LocalRest, createCustomRestInstance: createLocalRest } = createRest();

const localRest = createLocalRest('https://api.example.com');

// Or create from existed
import { createRestInstance } from '@ts-fetcher/rest';

const localRest = createRestInstance('https://api.example.com');

Caching

If you need to cache your responses, download this

npm install @ts-fetcher/cache
# or
yarn add @ts-fetcher/cache
# or
bun add @ts-fetcher/cache
# or
pnpm add @ts-fetcher/cache

If you need redis

npm install @ts-fetcher/redis ioredis
# or
yarn add @ts-fetcher/redis ioredis
# or
bun add @ts-fetcher/redis ioredis
# or
pnpm add @ts-fetcher/redis ioredis

Create instance using 1 of ways

import { createRestInstance } from '@ts-fetcher/rest';
import { LocalCache, RedisCache } from '@ts-fetcher/cache';

// Local cache
const localRest = createRestInstance('https://api.example.com', {
  cache: new LocalCache(),
});

// Or Redis
const redisRest = createRestInstance('https://api.example.com', {
  cache: new RedisCache({
    host: 'redis',
    port: 6379,
  }),
});

Set global options for each request

const localRest = createRestInstance('https://api.example.com', {
  cache: new LocalCache(),
  // this options will applied to all requests
  defaultRequestOptions: {
    headers: {
      Authorization: 'PvashkaTokenApzdClan',
    },
  },
});

Making requests

  1. Basic requests
await rest.get('/data');
  1. Typed requests
interface User {
  id: number;
  name: string;
}

interface UpdateUserDto {
  name: string;
}

// Typed GET
const { data } = await rest.get<User>('/users/1');

// Typed POST/PUT/PATCH
await rest.post<User, UpdateUserDto>('/users', {
  body: {
    name: 'John',
  },
});
  1. Cached requests
await rest.get('/users', {
  cache: {
    cacheKey: 'idk',
    // if not provided -> it will cached forever
    ttl: 500,
  },
});

Interceptors

You may familar with interceptors concepts in axios. They allows to mutate response/request during request lifecycle

Usage:

import { createCache, createRest, RequestInterceptor, ResponseInterceptor } from '@ts-fetcher/rest';

const ReqInterceptor: RequestInterceptor = (options) => {
  return {
    ...options,
    headers: {
      Authorization: "Bearer superprivate-token"
    }
  };
};

const NextReqInterceptor: RequestInterceptor = (options) => {
  return {
    ...options
    next: true
  };
};

const ResInterceptor: ResponseInterceptor = (data) => {
  return {
    ...data,
    overrided: true
  }
};

const const NextResInterceptor: ResponseInterceptor = (data) => {
  return {
    ...data,
    next: true
  }
};

const {
  CustomRest: ExampleRest,
  createCustomRestInstance: createExampleRestInstance,
} = createRest({
  cache: createCache('local'),
  // This interceptors are global, they will work for all request with this rest
  interceptors: {
    request: [ReqInterceptor],
    response: [ResInterceptor]
  },
});

const exampleRest = createOtakuReactionRestInstance('https://api.example.com');

await exampleRest.get("/path", {
  interceptors: {
    // This interceptors are local, they will work for only for this request
    request: [NextReqInterceptor],
    response: [NextResInterceptor]
  }
})

Response Format

{
  data: T,        // Response data
  success: boolean, // Similar to response.ok
  cached: boolean   // Whether data came from cache
}