2.0.0 • Published 9 years ago

promised-rest-client v2.0.0

Weekly downloads
2
License
MIT
Repository
github
Last release
9 years ago

Promised Rest Client

A simple rest client I, @thecaddy, use to hit apis that return json

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)
})
2.0.0

9 years ago

1.2.0

9 years ago

1.0.3

9 years ago

1.0.2

9 years ago

1.0.1

9 years ago

1.0.0

9 years ago