2.0.0 • Published 4 months ago

@financial-times/n-fetch v2.0.0

Weekly downloads
1,169
License
ISC
Repository
-
Last release
4 months ago

n-fetch CircleCI

This package is a wrapper for node-fetch and provides an interface for fetching resources server side.

Additional features:

  • If the resouce returns JSON, then the response will be sent as JSON automatically
  • Errors are logged to the console using n-logger

Requirements

  • Node version defined by engines.node in package.json. Run command nvm use to switch your local Node version to the one specified in .nvmrc.

Installation

git clone git@github.com:Financial-Times/n-fetch.git
cd n-fetch
make install

Development

Testing

In order to run the tests locally you'll need to run:

make test

Install from NPM

npm install --save @financial-times/n-fetch

Usage

const fetch = require('@financial-times/n-fetch');

fetch('https://api.fastly.com/public-ip-list', {
    method: 'GET',
    headers: {},        // request headers. format is the identical to that accepted by the Headers constructor (see below)
    body: null,         // request body. can be null, a string, a Buffer, a Blob, or a Node.js Readable stream
    redirect: 'follow', // set to `manual` to extract redirect headers, `error` to reject redirect
    signal: null,       // pass an instance of AbortSignal to optionally abort requests
    follow: 20,         // maximum redirect count. 0 to not follow redirect
    timeout: 0,         // req/res timeout in ms, it resets on redirect. 0 to disable (OS limit applies). Signal is recommended instead.
    compress: true,     // support gzip/deflate content encoding. false to disable
    size: 0,            // maximum response body size in bytes. 0 to disable
    agent: null         // http(s).Agent instance or function that returns an instance (see below)
}).then((data) => {
    console.log(data);
}).catch((error) => {
    console.log(error);
});

Documentation

This library exports a single default method with the following arguments and returns a promise.

  • input - A string representing the URL for fetching
  • init - an object with the request options
2.0.0

4 months ago

1.0.1

5 months ago

1.0.0

10 months ago

1.0.0-beta.14

11 months ago

1.0.0-beta.13

1 year ago

1.0.0-beta.12

2 years ago

1.0.0-beta.11

2 years ago

1.0.0-beta.10

3 years ago

1.0.0-beta.9

4 years ago

1.0.0-beta.8

4 years ago

1.0.0-beta.7

6 years ago

1.0.0-beta.6

6 years ago

1.0.0-beta.5

6 years ago

1.0.0-beta.4

7 years ago

1.0.0-beta.3

7 years ago

1.0.0-beta.2

7 years ago