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

@popovmp/client-request

v1.2.0

Published

Client request for NodeJS

Downloads

18

Readme

Client-Request

A simple client request library for node.js.

It parses the body according to the content type and supports various HTTP methods.

Installation

npm install @popovmp/client-request

Features

  • Support for GET, POST, PUT, HEAD requests
  • Automatic content type detection and parsing
  • Automatic decompression (gzip, deflate, brotli, zstd)
  • JSON and form data support
  • Configurable timeouts
  • TypeScript support
  • No external dependencies (except for request parsing)

API Reference

All functions accept optional headers as the last parameter. If no headers are provided, an empty object {} is used.

HEAD request

async function requestHead(url, headers?)

import { requestHead } from '@popovmp/client-request';

const url = "https://httpbin.org/get";
const headers = {"Accept": "application/json"}; // optional

const res = await requestHead(url, headers);
console.log(res.statusCode); // 200

GET request

async function requestGet(url, headers?)

import { requestGet } from '@popovmp/client-request';

const url     = "https://httpbin.org/get?foo=bar";
const headers = {"Accept": "application/json"}; // optional

const res = await requestGet(url, headers);
console.log(res.response.args); // { foo: 'bar' }

POST request

async function requestPost(url, data, headers?)

import { requestPost } from '@popovmp/client-request';

const url     = "https://httpbin.org/post?foo=bar";
const body    = "Hello, World!";
const headers = {"Content-Type": "text/plain"}; // optional

const res  = await requestPost(url, body, headers);
console.log(res.response);

PUT Request

async function requestPut(url, data, headers?)

Same as POST request but uses PUT method.

import { requestPut } from '@popovmp/client-request';

const url  = "https://httpbin.org/put";
const data = {message: "Hello, World!"};

const res = await requestPut(url, data);
console.log(res.response);

POST JSON request

async function requestJson(url, data, headers?)

import { requestJson } from '@popovmp/client-request';

const url     = "https://httpbin.org/post?foo=bar";
const json    = {number: 42, text: "foo", list: [1, 2], object: {bar: "baz"}};
const headers = {User-Agent: "Request-Service"}; // optional

const res  = await requestJson(url, json, headers);
console.log(res.response.json); // parsed JSON response

POST form URL encoded request

async function requestForm(url, formData, headers?)

import { requestForm } from '@popovmp/client-request';

const url     = "https://httpbin.org/post?foo=bar";
const form    = {number: 42, text: "foo", list: [1, 2]};
const headers = {User-Agent: "Request-Service"}; // optional

const res  = await requestForm(url, form, headers);
console.log(res.response.form); // parsed form data

Response Format

All functions return a ClientRequestResponse object with the following properties:

{
  response     : any,    // Parsed response body (depends on content-type)
  headers      : object, // Response headers
  host         : string, // Request host
  method       : string, // HTTP method used
  path         : string, // Request path
  protocol     : string, // Protocol used (http: or https:)
  statusCode   : number, // HTTP status code
  statusMessage: string, // HTTP status message
}

Timeout Configuration

By default, requests timeout after 30 seconds. You can customize this by adding a Request-Timeout header with the timeout in seconds:

const headers = {
  "Request-Timeout": "10" // 10 seconds timeout
};

const res = await requestGet(url, headers);

Compression Support

The library automatically handles compressed responses from servers:

  • gzip - Most common compression
  • deflate - Standard compression
  • brotli - Modern compression (br)
  • zstd - New fast compression

Simply include the appropriate Accept-Encoding header:

const headers = {
  "Accept-Encoding": "gzip, deflate, br, zstd"
};

const res = await requestGet(url, headers);
// Response is automatically decompressed

If no Accept-Encoding header is provided, responses are processed as-is.

Error Handling

The library throws errors for:

  • Network connectivity issues
  • Request timeouts
  • Invalid URLs
  • Server errors
  • Decompression failures
try {
  const res = await requestGet("https://invalid-url");
} catch (error) {
  console.error("Request failed:", error.message);
}