Commit 164370b4 authored by Ty Abonil's avatar Ty Abonil
Browse files

added README

parent a3c3f5a3
Loading
Loading
Loading
Loading

README.md

0 → 100644
+45 −0
Original line number Diff line number Diff line
# Request-Promise

A Promises/A XHR wrapper for Bluebird and Request

[Bluebird](https://github.com/petkaantonov/bluebird) and [Request](https://github.com/mikeal/request) are pretty awesome, but I found myself using the same design pattern.  This is a simple wrapper that takes in a request options object (or URI string), and returns a chainable promise.  By default, http response codes other than 200 and 201 will cause the promise to be rejected.  This can be over-ridden by setting 'options.simple' to `false`.

## Examples

``` js
var rp = require('request-promise'), 

rp('http://www.google.com')
    .then(console.dir)
    .catch(console.error);

//'GET's and displays google.com

var options = {
    uri : 'http://posttestserver.com/post.php',
    method : 'POST'
}; 

rp(options)
    .then(console.dir)
    .catch(console.error);

//displays response from server after post

options.transform : function (data) { return data.length ;}

rp(options)
    .then(console.dir)
    .catch(console.error);

//transform is called just before promise is fulfilled
//displays lengthg of response from server after post

```

## Installation

`npm install request-promise`


## MIT Licenced
 No newline at end of file
+3 −2
Original line number Diff line number Diff line
@@ -6,7 +6,8 @@ function rp(options) {
        'GET' : [200],
        'HEAD' : [200],
        'PUT' : [200, 201],
        'POST' : [200, 201]
        'POST' : [200, 201],
        'DELETE' : [200, 201]
    }, c = {}, i;
    if (typeof options === 'string') {
        c.uri = options;
+1 −0
Original line number Diff line number Diff line
@@ -15,6 +15,7 @@
    "promise",
    "request"
  ],
  "readmeFilename": "README.md",
  "author": "Ty Abonil",
  "license": "MIT",
  "dependencies": {

readme.md

0 → 100644
+45 −0
Original line number Diff line number Diff line
# Request-Promise

A Promises/A XHR wrapper for Bluebird and Request

[Bluebird](https://github.com/petkaantonov/bluebird) and [Request](https://github.com/mikeal/request) are pretty awesome, but I found myself using the same design pattern.  This is a simple wrapper that takes in a request options object (or URI string), and returns a chainable promise.  By default, http response codes other than 200 and 201 will cause the promise to be rejected.  This can be over-ridden by setting 'options.simple' to `false`.

## Examples

``` js
var rp = require('request-promise'), 

rp('http://www.google.com')
    .then(console.dir)
    .catch(console.error);

//'GET's and displays google.com

var options = {
    uri : 'http://posttestserver.com/post.php',
    method : 'POST'
}; 

rp(options)
    .then(console.dir)
    .catch(console.error);

//displays response from server after post

options.transform : function (data) { return data.length ;}

rp(options)
    .then(console.dir)
    .catch(console.error);

//transform is called just before promise is fulfilled
//displays lengthg of response from server after post

```

## Installation

`npm install request-promise`


## MIT Licenced
 No newline at end of file