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

request-half

v1.1.2

Published

functional-friendly, fetch-like nodejs native request

Downloads

15

Readme

request-half

asynchronous, functional-friendly request(), parse() only using node-native modules

  • It is a node module. Browser environment is not supported.
  • It uses node internal modules: http, https, stream, zlib
  • request() parameters are similar to http.request() and fetch()
    (If you are sending JSON body, you should set header content-type: application/json)
  • request() uses https.request() if url starts with 'https'
  • Unlike fetch(), request() returns IncomingMessage which is original http.request() returns.
  • parse() parses gzip automatically if 'content-encoding' header is 'gzip' or 'deflate'.
  • parse() is curried. you can use this function like .then(parse('json'))
  • parse() can parse 'json'|'utf8'|'ucs2'|'utf-8'|'ascii'|'ucs-2'|'utf16le'|'utf-16le'|'latin1'|'binary'|'base64'|'hex'|'buffer';

Installation

Yarn

yarn add request-half

NPM

npm install -S request-half

Available functions

export function request(url: string | URL, options?: RequestOptions): Promise<IncomingMessage>;
export function request(options: RequestOptions): Promise<IncomingMessage>;

export function parse(message: IncomingMessage): Promise<string>;
export function parse(): (message: IncomingMessage) => Promise<string>;
export function parse<T>(type: 'json'): (message: IncomingMessage) => Promise<T>;
export function parse(type: 'buffer'): (message: IncomingMessage) => Promise<Buffer>;
export function parse(type: ResolveType): (message: IncomingMessage) => Promise<string>;
export function parse<T>(type: 'json', message: IncomingMessage): Promise<T>;
export function parse(type: 'buffer', message: IncomingMessage): Promise<Buffer>;
export function parse(type: ResolveType, message: IncomingMessage): Promise<string>;

Examples

const { request, parse } = require('request-half');
// or import { request, parse } from 'request-half';

const url = 'some url here';

// basic GET request
const response = await request(url);

// return value of request() would be http.IncomingMessage
console.log(response.statusCode, response.headers);

// send POST request only with the first argument as `options`
const options = { hostname: '127.0.0.1', port, path: '/', method: 'POST', body: '{ "test": "ok" }' };
const response2 = await request(options);

// pass to parse() function
const object2 = await parse('json', response);

// curry parse function
const object = await request(url).then(parse('json'));

// take response as buffer
const buffer = await request(url).then(parse('buffer'));

// parse as utf-8 text
const text2 = await request(new URL(url)).then(parse('utf8'));

// default type is 'utf8'
const text = await request(new URL(url)).then(parse());

// even without currying, default type is 'utf8'
const response = await request(new URL(url));
const text2 = await parse('utf8', response);
const text3 = await parse(response);

// POST Message
const result1 = await request('http://example.com/article', {
  method: 'POST',
  headers: { 'Content-type': 'application/json' },
  body: JSON.stringify({ title: 'Hello, world', body: 'Use half to request, then else half to parse.' }),
}).then(parse('json'));

// GET Message
const querystring = require('querystring');
const url = `http://example.com/article?${querystring.stringify({ title: 'Hello', orderBy: 'date' })}`;
const result2 = await request(url).then(parse('json'));

// HTTPS is also OK.
const result3 = await request('https://example.com/article/1').then(parse('json'));