Giter VIP home page Giter VIP logo

teeny-request-promise's Introduction

teeny-request-promise

This package is a work in progress


A teeny tiny Promise wrapper (and compat layer) around Google's teeny-request library

https://github.com/googleapis/teeny-request


Installing

npm install -S teeny-request-promise teeny-request

Usage

options - Any of the current teeny-request options, plus a few additional aliases. These are not complete, though not all of the original request options will be supported:

  • options.form
    • alias for options.body
  • options.resolveWithFullResponse
    • When truthy, resolves with the full response object, otherwise returns with just the body

Promises:

const request = require('teeny-request-promise');

// promise
request({
    url: 'your-api',
    ...otherOptions
}).then((body) => {
    // handle the body response
}).catch((error) => {
    // handle any errors
});

request.post({
    uri: 'some-uri',
    form: {
        attribute: true,
        anotherThing: 'yes'
    },
    resolveWithFullResponse: true,
}).then((response) => {
    // handle the full response
    // i.e. response.body
}).catch((error) => {
    // handle your errors
});

Async/Await

const request = require('teeny-request-promise');

async function yourAsyncContextOrCallbackOrWhateverYouWantItsReallyUpToYou() {
    // send up generic get request, but only pass back the response.body
    const body = await request({
        url: 'your-api',
        ...otherOptions
    });

    // send up a form post, but get the full response back
    const fullResponse = await request.post({
        uri: 'some-uri',
        form: {
            attribute: true,
            anotherThing: 'yes'
        },
        resolveWithFullResponse: true,
    });
}

Progress

See the /TODO.md for milestones as to the progress of this package.

teeny-request-promise's People

Contributors

f1yn avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.