Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

teeny-request

googleapis34.4mApache-2.010.1.0TypeScript support: included

Like request, but smaller.

request, node-fetch, fetch

readme

Build Status

THIS REPOSITORY AND PACKAGE WILL BE DEPRECATED IN JULY 2024. RELEVANT FUNCTIONALITIES HAVE BEEN MOVED TO GOOGLEAPIS/GAXIOS

teeny-request

Like request, but much smaller - and with less options. Uses node-fetch under the hood. Pop it in where you would use request. Improves load and parse time of modules.

const request = require('teeny-request').teenyRequest;

request({uri: 'http://ip.jsontest.com/'}, function (error, response, body) {
  console.log('error:', error); // Print the error if one occurred
  console.log('statusCode:', response && response.statusCode); // Print the response status code if a response was received
  console.log('body:', body); // Print the JSON.
});

For TypeScript, you can use @types/request.

import {teenyRequest as request} from 'teeny-request';
import * as r from 'request'; // Only for type declarations

request({uri: 'http://ip.jsontest.com/'}, (error: any, response: r.Response, body: any) => {
  console.log('error:', error); // Print the error if one occurred
  console.log('statusCode:', response && response.statusCode); // Print the response status code if a response was received
  console.log('body:', body); // Print the JSON.
});

teenyRequest(options, callback)

Options are limited to the following

  • uri
  • method, default GET
  • headers
  • json
  • qs
  • useQuerystring
  • timeout in ms
  • gzip
  • proxy
request({uri:'http://service.com/upload', method:'POST', json: {key:'value'}}, function(err,httpResponse,body){ /* ... */ })

The callback argument gets 3 arguments:

  • An error when applicable (usually from http.ClientRequest object)
  • A response object with statusCode, a statusMessage, and a body
  • The third is the response body (JSON object)

defaults(options)

Set default options for every teenyRequest call.

let defaultRequest = teenyRequest.defaults({timeout: 60000});
      defaultRequest({uri: 'http://ip.jsontest.com/'}, function (error, response, body) {
            assert.ifError(error);
            assert.strictEqual(response.statusCode, 200);
            console.log(body.ip);
            assert.notEqual(body.ip, null);

            done();
        });

Proxy environment variables

If environment variables HTTP_PROXY, HTTPS_PROXY, or NO_PROXY are set, they are respected.

Building with Webpack 4+

Since 4.0.0, Webpack uses javascript/esm for .mjs files which handles ESM more strictly compared to javascript/auto. If you get the error Can't import the named export 'PassThrough' from non EcmaScript module, please add the following to your Webpack config:

{
    test: /\.mjs$/,
    type: 'javascript/auto',
},

Motivation

request has a ton of options and features and is accordingly large. Requiring a module incurs load and parse time. For request, that is around 600ms.

Load time of request measured with require-so-slow

teeny-request doesn't have any of the bells and whistles that request has, but is so much faster to load. If startup time is an issue and you don't need much beyond a basic GET and POST, you can use teeny-request.

Thanks

Special thanks to billyjacobson for suggesting the name. Please report all bugs to them. Just kidding. Please open issues.

changelog

Changelog

10.1.0 (2025-04-07)

Features

10.0.0 (2025-02-15)

⚠ BREAKING CHANGES

  • upgrade to Node 18 (#353)

Miscellaneous Chores

9.0.0 (2023-07-20)

⚠ BREAKING CHANGES

  • move minimum version to node 14 (#312)

Miscellaneous Chores

8.0.3 (2023-02-17)

Bug Fixes

  • Use pipeline in place of pipe to better handle cleanup / errors (#299) (31d9002)

8.0.2 (2022-09-09)

Bug Fixes

8.0.1 (2022-08-23)

Bug Fixes

8.0.0 (2022-05-09)

⚠ BREAKING CHANGES

  • drop node 10, update typescript to 4.6.3 (#279)

Build System

  • drop node 10, update typescript to 4.6.3 (#279) (6f12739)

7.2.0 (2022-03-31)

Features

7.1.3 (2021-09-24)

Bug Fixes

  • deps: update dependency http-proxy-agent to v5 (#253) (c84dff4)

7.1.2 (2021-09-10)

Bug Fixes

7.1.1 (2021-06-30)

Bug Fixes

7.1.0 (2021-05-19)

Features

  • add gcf-owl-bot[bot] to ignoreAuthors (#224) (3e7424f)

Bug Fixes

  • Buffer is allow as body without encoding to string (#223) (d9bcdc3)

7.0.1 (2020-09-29)

Bug Fixes

7.0.0 (2020-06-01)

⚠ BREAKING CHANGES

  • dropping support for Node.js 8.x

Features

  • pass agent options when using agent pool config (#149) (38ece79)
  • warn on too many concurrent requests (#165) (88ff2d0)

Bug Fixes

Build System

6.0.3 (2020-03-06)

Bug Fixes

6.0.2 (2020-02-10)

Bug Fixes

  • deps: update dependency https-proxy-agent to v5 (#128) (5dcef3f)

6.0.1 (2020-01-24)

Bug Fixes

  • deps: update dependency http-proxy-agent to v4 (#121) (7caabcf)

6.0.0 (2020-01-11)

⚠ BREAKING CHANGES

  • remove console log and throw instead (#107)

Bug Fixes

  • remove console log and throw instead (#107) (965beaa)

5.3.3 (2019-12-15)

Bug Fixes

  • deps: update dependency http-proxy-agent to v3 (#104) (35a47d8)
  • deps: update dependency https-proxy-agent to v4 (#105) (26b67af)
  • docs: add jsdoc-region-tag plugin (#98) (8f3c35a)

5.3.2 (2019-12-05)

Bug Fixes

5.3.1 (2019-10-29)

Bug Fixes

  • correctly set compress/gzip option when false (#95) (72ef307)

5.3.0 (2019-10-09)

Bug Fixes

  • deps: update dependency https-proxy-agent to v3 (#89) (dfd52cc)

Features

5.2.1 (2019-08-14)

Bug Fixes

  • types: make types less strict for method (#76) (9f07e98)

5.2.0 (2019-08-13)

Bug Fixes

  • if scheme is http:// use an HTTP agent (#75) (abdf846)
  • remove unused logging (#71) (4cb4967)
  • undefined headers breaks compatibility with auth (#66) (12901a0)

Features

  • support lazy-reading from response stream (#74) (f6db420)
  • support reading from the request stream (#67) (ae23054)

Reverts

  • do not pipe fetch response into user stream (#72) (6ec812e)

5.1.3 (2019-08-06)

Bug Fixes

  • duplex stream does not implement methods like _read (#64) (22ee26c)

5.1.2 (2019-08-06)

Bug Fixes

  • types: expand method and header types (#61) (c04d2f1)

5.1.1 (2019-07-23)

Bug Fixes

  • support lowercase proxy env vars (#56) (0b3e433)

5.1.0 (2019-07-19)

Features

5.0.0 (2019-07-15)

⚠ BREAKING CHANGES

  • this is our first release since moving into googleapis org; in the theme of "better safe than sorry" we're releasing as 5.0.0.

Bug Fixes

  • export types independent of @types/request (#44) (fbe2b77)

Reverts

  • revert 4.0.0 release in favor of 5.0.0 release (#52) (f24499e)