1.0.1 • Published 8 years ago

promisified-rest-client v1.0.1

Weekly downloads
1
License
MIT
Repository
github
Last release
8 years ago

Promised Rest Client

A simple rest client I, @pharzam, use to hit APIs that return json. I forked it form @thecaddy ", the major modified that I made is about reject function. In this new package I return the error as an object with code & message that object is the body of response in catch

API

var data = require('promised-rest-client')(myUrl);

//Overloaded Method uses data.get(obj) data.get(url, obj)

//Remaining CRUD data.update(...) //PUT data.insert(...) //POST data.post(...) //POST data.delete(...) //DELETE

The object takes several parameters:

var obj = { url: 'path/to/my/thing', qs: { myquery: 'string equals this' }, body: { mybody: { hasmore: 'things', awesome: true } } }

Usage

All queries return a promise.

Example:

var data = require('promised-rest-client')({url: 'http://woohoo.com/'})

//Submits a get request to 'http://woohoo.com/bam/pow/shoot?count=true' data.get({ url: 'bam/pow/shoot', qs:{ count: true } }).then(function(resp){ //Submits a get request to 'http://woohoo.com/bam/pow/shoot' //with body json { count: false } return data.update('bam/pow/bang', { body: { count: false } }) }).then(function(resp){ console.log(resp) }).catch(function(err){ console.error(err) })