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 🙏

© 2025 – Pkg Stats / Ryan Hefner

express-http-client

v0.3.6

Published

middleware style interceptor; fetch based 0 dependancy imperative light weight http handler.

Downloads

27

Readme

Express Http Client

npm badge compatibility badge gzipped_size badge production_size badge License badge Contributor Covenant

A light-weight javascript http request library built in conscious of middleware design pattern. (requires fetch api)

This project aims to reduce user mental effort and give user more control over the request process by provide only minimal features.

The middleware usage is as intuitive as using expressjs server middleware by using next() to pass control to the next middleware.

It will minimize effort to migrate from fetch to this library and work out of the box by just simply rename fetch to request in your project.

Quick Start

one time request

import { request } from 'express-http-client';

await request(
    "https://example.com/api/v1/posts",
    {
        method: 'GET',
        headers: {
            'Authorization': 'Bearer ' + refresh
        }
    },
    // response interceptors
    [
        //example response interceptor middleware
        (data, next) => {
            data.response.json().then(json => {
                console.log(json);
                next();
            }).catch(error => {
                next(error);
            });
        }
    ],
    // request interceptors
    []
);

httpClient

import {httpClient as expressHttpClient, logger, mockResponse} from 'express-http-client';

//create a new http client instance, you can create multiple http client instance for different purpose
let httpClient = expressHttpClient();

//add request interceptor middleware: example to add authorization header
httpClient.addRequestInterceptor(async (data, next) => {
    data.request = new Request(data.request, {
        // You can override any request properties here
        headers: new Headers({
            ...Object.fromEntries(data.request.headers.entries()),
            'Authorization': `Bearer token`
        }),
    });
    next();
});

//add response interceptor middleware: example
httpClient.addResponseInterceptor(
    //use built in logger interceptor middleware to log the request and response
    logger(),
);

httpClient = httpClient.create("replace with your base url");

let response = await httpClient.send(`/api/v1/posts`);

Api

interceptor function

parameters

  • data: the data object
    • request: the request object
    • response: the response object
    • store: a map store for data persistence between interceptors
  • next: the next function

built in interceptor functions

logger

mockResponse

import {httpClient as expressHttpClient, logger, mockResponse} from 'express-http-client';

let httpClient = expressHttpClient();

httpClient.addResponseInterceptor(
    mockResponse(
        true,
        // supply the mock response mapping object here(url.method -> response)
        {
            "http://example.com/api/v1/posts": {
                //mock response for GET request
                "GET": ()=> new Response(JSON.stringify(
                    //mock response data
                ))
            },
            "http://example.com/api/v1/posts": {
                //mock response for all request
                "ALL": ()=> new Response(JSON.stringify(
                    //mock response data
                ))
            },
        }
    )
)