Socket
Book a DemoInstallSign in
Socket

futoin-request

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

futoin-request

AsyncSteps friendly wrapper of 'request' package

latest
Source
npmnpm
Version
2.1.2
Version published
Weekly downloads
2
Maintainers
1
Weekly downloads
 
Created
Source

NPM Version NPM Downloads Build Status stable

NPM

About

FutoIn AsyncSteps friendly wrapper of request.

Documentation --> FutoIn Guide

Author: Andrey Galkin

Installation for Node.js

Command line:

$ npm install futoin-request --save

or:

$ yarn add futoin-request --save

Browser installation

The module can be used with webpack or any other CommonJS packer. However, please ensure to use ES6->ES5 transpilation for older browsers.

Pre-packed UMD module is available in dist/futoin-request.js (stripped ~180KB from over 1MB).

Note: please note that pre-packed dist is heavily stripped of dependencies and most features of request library is not expected to work due not minimal use case in browsers:

  • MIME type detection based on upload file name
  • AWS request signing feature
  • HAR feature
  • HTTP Signature feature
  • HAWK feature
  • Proxy/Tunnel feature
  • HTTP digest auth (large crypto dependency)
  • OAuth
  • tough-cookie

You can always use own webpack build.

Examples

const $as = require('futoin-asyncsteps');
const $as_request = require('futoin-request');

$as().add((as) => {
    // Very basic
    $as_request(as, 'https://httpbin.org/get');
    as.add((as, rsp, body) => console.log(body));
    
    // As usual
    $as_request.post(as, {
        url: 'https://httpbin.org/post',
        json: {a: 1, b: 2},
    });
    as.add((as, rsp, body) => console.log(body));
    
    // With callback for request as stream manipulation
    $as_request.post(as, {
        url: 'https://httpbin.org/post',
        headers: { 'content-length': 4 },
    }, (req) => req.end('test') );
    as.add((as, rsp, body) => console.log(body));    
}).execute();

API documentation

API is absolutely the same as for original request package except that:

  • The first parameter must be a reference of AsyncSteps interface type.
  • A next step receiving (as, rsp, body) => {} must be added instead of result callback.
  • Error is thrown through AsyncSteps#error(), if detected.
  • HTTP status != 200 is error as well.
  • Request object is not returned, but passed to optional callback (third argument).

Additional notes:

  • Request is properly canceled on AsyncSteps#cancel() or timeout
  • Error info details
    • error type - RequestError
    • error object should be available through standard as.state.last_exception convention
    • as.state.last_response is set with response object
  • Browser provides $as_request global reference

Members

request

window.FutoIn.request - browser-only reference to futoin-request module

$as_request

window.$as_request - browser-only reference to futoin-request module

request

window.FutoIn.request - browser-only reference to futoin-request module

Kind: global variable

$as_request

window.$as_request - browser-only reference to futoin-request module

Kind: global variable

Keywords

futoin

FAQs

Package last updated on 15 Mar 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts