@transclusion/request
TypeScript icon, indicating that this package has built-in type declarations

1.1.4 • Public • Published

@transclusion/request

A minimal xhr-based library for making observable requests in the browser and in Node.js.

# Install with npm
npm install @transclusion/request

# Install with yarn
yarn add @transclusion/request

build status npm version

Usage

import {get} from '@transclusion/request'

// Make a request observable
const req = get('https://www.google.com')

// The request will be sent whenever it is subscribed to
const subscription = req.subscribe({
  next(res) {
    if (res.readyState === 3) {
      console.log(`Loaded: ${(res.bytesLoaded / res.bytesTotal) * 100}%`)
    }

    if (res.readyState === 4) {
      console.log(`Text: ${res.text}`)
    }
  },
  error(err) {
    console.error(err.stack)
  },
  complete() {
    console.log('DONE')
  },
})

// To abort the request at any time, simply unsubscribe:
subscription.unsubscribe()

License

MIT © Marius Lundgård

Readme

Keywords

none

Package Sidebar

Install

npm i @transclusion/request

Weekly Downloads

0

Version

1.1.4

License

MIT

Unpacked Size

110 kB

Total Files

22

Last publish

Collaborators

  • mariuslundgard