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

@anissoft/request

v2.0.7

Published

Wrap on top of the standart fetch API with few tweaks

Downloads

1,009

Readme

Welcome to @anissoft/request 👋

Wrap on top of the standart fetch API with few tweaks, which make may life easier

Installation

npm install @anissoft/request

Usage

You just need to intitalize and export request function:

// request.ts
import { initialize } from "@anissoft/request";
export const request = initialize(fetch, options);

After it you can import and use it:

import request from "../request";

(async () => {
  try {
    const response1 = await request("https://example.com/api/method", {
      method: "POST",
      body: { foo: "bar" },
      isOk: ({ status }) => status < 400,
      shouldThrow: true,
    });
    console.log("Response body:", response1.text());
    console.log("Parsed json:", response1.json());
  } catch (response1) {
    console.error(response1.statusText);
  }

  // equivalent for
  const response2 = await fetch("https://example.com/api/method", {
    method: "POST",
    headers: {
      "Content-Type": "application/json",
    },
    body: JSON.stringify({ foo: "bar" }),
  });
  if (response2.status >= 400) {
    console.error(response2.statusText);
  } else {
    const text = await response2.text();
    console.log("Response body:", text);
    try {
      console.log("Parsed json:", JSON.parse(text));
    } catch (e) {
      console.log("Parsed json:", undefined);
    }
  }
})();

Features

isOk

You can specify custom condition in RequestInit to define if response is ok:

request("https://example.com/api/method", {
  isOk: ({ status }) => status < 400 || status === 429,
});

shouldThrow

If shouldThrow set true in RequestInit - request will be rejected if response.ok is falsy:

request("https://example.com/api/method", {
  shouldThrow: true,
}).catch((response) => {
  console.log(response.status);
});

Stringify object-like body

... and automaticaly set 'Content-Type' header in 'application/json':

request("https://example.com/api/method", {
  method: "POST",
  body: { foo: "bar" },
});

Sync .json() and .text() methods

.json() and .text() methods contains preparsed data and can be executed synchronously multiple times:

const response = request("https://example.com/api/method");

console.log(response.text());
console.log(response.json());

actions object

You can assign actions for specific status codes, or general events:

request("https://example.com/api/method", {
  method: "POST",
  isOk: ({ status, ok }) => ok || status === 429,
  actions: {
    ok: (response) => {
      console.log("Executes if response.ok === true, or if isOk() returns true");
    },
    "403": (response) => {
      console.log("Executes if response.status === 403");
    },
    "401,402": (response) => {
      console.log("Executes if response.status is 401 or 402");
    },
    "500-516": (response) => {
      console.log("Executes if response.status >= 500 and response.status <= 516");
    },
    network: (response) => {
      console.log("Executes network exception was thrown");
    },
    default: (response) => {
      console.log("Executes in all other cases");
    },
  },
});

Helpers

getParameterByName(name: string[, url: string])

Returns the last value of query parameter from given url. If no url specified - will use global location.href in browser, or empty string in NodeJS.

const { getParameterByName } = require("@anissoft/request");

const search = getParameterByName("search", "https://example.com/api/method?search=123");
console.log(search); // '123';

Author

👤 Alexey Anisimov

🤝 Contributing

Contributions, issues and feature requests are welcome!

Feel free to check issues page.