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

http-batcher

v0.0.2

Published

HTTP Request Batcher for SPA

Readme

HTTP Batcher

HTTP Request Batcher for SPA

It's for existing project not using GraphQL (maybe Apollo is better)

Install

npm i http-batcher

Usage

Define type of arguments of request. any form, even any is allowed.

// for example
interface Request {
  method: 'GET' | 'POST' | 'PUT' | 'DELETE';
  url: 'string';
  parameter?: string;
}

Create Batcher instance with previously defined type, and options

const batcher = new Batcher<Request>(options);

and queue to the batcher instead of firing HTTP request

batcher.queue({
  method: 'GET',
  url: './notice/top/1',
});

Example

const API_ENDPOINT = './api';
const API_ENDPOINT_BATCH = './api-batch';

/*
 * API Call may includes HTTP method, URL, parameters, ...
 */
type APICall = [key: string, param: any];

function request([key, data]: APICall): Promise<any> {
  return XHR(`${API_ENDPOINT}/${key}`, data);
}

/*
 * To use this library, Batch API needed on the backend
 */
function batchRequest(data: APICall[]): Promise<any[]> {
  return XHR(API_ENDPOINT_BATCH, data);
}

/*
 * Create Batcher instance
 * See Options for details
 */
const defaultBatcher = new Batcher<APICall>({
  defaultDelay: 1,
  minDelay: 3,
  maxDelay: 100,
  process: batchRequest,
  preferSingle: request,
});

/*
 * Existing code (maybe) has a common function to call API
 * Change it to use the Batcher!
 * It batches nearly concurrent API calls into one HTTP request
 */
export default function API<Key extends keyof API_DEFINITION>(
  key: Key,
  param: API_DEFINITION[Key]['request'],
  batcher = defaultBatcher,
): Promise<API_DEFINITION[Key]['response']> {
  // Queuing to the batcher instead of firing actual HTTP request
  return batcher.queue<API_DEFINITION[Key]['response']>([key, param]);
}

Options

  • defaultDelay - Time to wait for others to be queued, by millisecond. default 1
  • minDelay - Minimum time to wait from the first queued time in the batch. default 0
  • maxDelay - Maximum time to wait from the first queued time. required
  • maxCount - Maximum batch size. default Infinity, UNSTABLE
  • process - Actual executor for queued tasks. required
    • Function accepts array of the type of arguments of request and returns Promise for array contains each result
    • Some pre/post processing (e.g. remove redundant request by idempotency) can also be performed here
  • preferSingle - If specified, used instead of process if count of requests of the batch is 1. optional
    • Function accepts the type of arguments of request and returns Promise for the result
    • Not required~~, but slight reduction in server side load can be expected?~~

Requirements

Typescript

License

Code licensed under the MIT License.