@mescribano/async-request
async-request is a wrapper for request that uses ES7 async functions.
Last updated 8 months ago by mescribano .
BSD-3-Clause · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install @mescribano/async-request 
SYNC missed versions from official npm registry.

additions

This particular modified version of async-request allows an extra option on call, 'secure' (boolean: true | false). If false, the necessary options to not reject unsecure certificates are passed onto the wrapped request object, which is unsettable from within the original async-request wrapper.

async-request

NPM version Travis build status Dependency Status

async-request is a wrapper for request that uses ES7 async functions.

Usage

let request = require('async-request'),
    response;

try {
    response = await request('http://gajus.com/');

    // response.statusCode
    // response.headers
    // response.body

    await request('http://gajus.com', {
        // This example demonstrates all of the supported options.
        // Request method (uppercase): POST, DELETE, ...
        method: 'POST',
        data: {
            foo: 'bar'
        },
        headers: {
            foo: 'bar'
        },
        proxy: 'http://127.0.0.1:8000',
        // To create a new cookie jar.
        cookieJar: true,
        // To use a custom/existing cookie jar.
        // https://www.npmjs.com/package/tough-cookie
        cookieJar: new tough.CookieJar()
    });
} catch (e) {

}

// Returns a wrapper for the request using predefined custom options.
request = request.defaults({headers: {foo: 'bar'}});

// Returns the current default options.
request.defaults();
// {foo: 'bar'}

// Makes a HTTP GET request with {foo: 'bar'} headers.
await request('http://gajus.com');

Debugging

async-request does not provide (expose) inbuilt debugging capabilities. Use a proxy (e.g. https://mitmproxy.org/) to intercept and analyze HTTP traffic.

API

Running

Async function behavior has been accepted into stage 1 ("Proposal") of the ECMASCript 7 spec process in January 2014. This means that it cannot be used out of the box with node.js or iojs without a transpiler.

This library is using Babel to compile ES7 code into ES5. Refer to the ./gulpfile.js.

Beware

This library has been created as part of ES7 async function proposal research. It covers basic use of request. I do not advise to use it in production, though I will be testing it in several private projects and update as I go – contributions are welcome too.

Current Tags

  • 1.2.0                                ...           latest (8 months ago)

1 Versions

  • 1.2.0                                ...           8 months ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (3)
Dev Dependencies (11)
Dependents (0)
None

Copyright 2014 - 2016 © taobao.org |