JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 2
  • Score
    100M100P100Q22255F
  • License MIT

HTTP fetch function as a pull stream

Package Exports

  • pull-fetch

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (pull-fetch) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

pull-fetch NPM version Build Status

HTTP fetch function for pull stream

pull(
  fetch.result('http://example.com/', { method: 'POST' }),
  pull.map(result => result.toString()),
  pull.log()
)

A fetch module for pull streams. It is inspired from whatwg fetch, but not closely related.

Installation

$ npm install --save pull-fetch

Usage

fetch(url, [options])

HTTP request the url and receive a response pull stream.

Options

All options are passed into http.request/https.request, in addition to:

  • body (String|Buffer|Object): Body of the HTTP request (objects get serialized).

Example

pull(
  // Make a POST request with a body:
  fetch('https://example.com', { method: 'POST', body: { foo: 123 } }),
  pull.mapAsync((resp, done) => {
    // Handle response stream in an async way
    return pull(resp, pull.collect(done))
  }),
  pull.log()
)

fetch.result(url, [options])

A wrapper around fetch that resolves the stream into a buffer. Parameters are the same.

Example

pull(
  fetch.result('https://example.com'),
  pull.log()
)

fetch.json(url, [options])

A wrapper around fetch.result that parses as JSON. Parameters are the same.

Example

pull(
  fetch.json('https://api.github.com/users/jamen', options),
  stringify(),
  pull.log()
)

License

MIT © Jamen Marz