Skip to content

Commit 87965f8

Browse files
committed
Post example with payload (Issue #59)
1 parent 02c73c7 commit 87965f8

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

README.md

+4-2
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,9 @@ rp('http://www.google.com')
5454

5555
var options = {
5656
uri : 'http://posttestserver.com/post.php',
57-
method : 'POST'
57+
method : 'POST',
58+
json: true,
59+
body: { some: 'payload' }
5860
};
5961

6062
rp(options)
@@ -377,7 +379,7 @@ We added io.js to our Travis CI build and all tests are green. However, they mos
377379

378380
The approx. 120 lines of code – on top of the well tested libraries Request and Bluebird – are covered by over 60 tests producing a test coverage of 100% and beyond. Additionally, the original tests of Request were executed on Request-Promise to ensure that we can call it "a drop-in replacement for Request". So yes, we did our best to make Request-Promise live up to the quality Request and Bluebird are known for.
379381

380-
However, there is one important design detail: Request-Promise passes a callback to each Request call which it uses to resolve or reject the promise. The callback is also registered if you don't use the promise features in a certain request. E.g. you may only use streaming: `rp(...).pipe(...)` As a result, [additional code](https://github.com/request/request/blob/master/request.js#L1010-L1059) is executed that buffers the streamed data and passes it as the response body to the "complete" event. If you stream [large quantities of data](https://github.com/request/request-promise/issues/53) the buffer grows big and that has an impact on your memory footprint. In these cases you can just `var request = require('request');` and use `request` for streaming large quantities of data.
382+
However, there is one important design detail: Request-Promise passes a callback to each Request call which it uses to resolve or reject the promise. The callback is also registered if you don't use the promise features in a certain request. E.g. you may only use streaming: `rp(...).pipe(...)` As a result, [additional code](https://github.com/request/request/blob/master/request.js#L1026-L1075) is executed that buffers the streamed data and passes it as the response body to the "complete" event. If you stream [large quantities of data](https://github.com/request/request-promise/issues/53) the buffer grows big and that has an impact on your memory footprint. In these cases you can just `var request = require('request');` and use `request` for streaming large quantities of data.
381383

382384
## Contributing
383385

test/spec/request-test.js

+5-3
Original file line numberDiff line numberDiff line change
@@ -969,12 +969,14 @@ describe('Request-Promise', function () {
969969

970970
options = {
971971
uri : 'http://localhost:4000/200',
972-
method : 'POST'
972+
method : 'POST',
973+
json: true,
974+
body: { some: 'payload' }
973975
};
974976

975977
return rp(options)
976978
.then(function (body) {
977-
expect(body).to.eql('POST /200');
979+
expect(body).to.eql('POST /200 - {"some":"payload"}');
978980
})
979981
.catch(function (err) {
980982
throw err;
@@ -989,7 +991,7 @@ describe('Request-Promise', function () {
989991

990992
return rp(options)
991993
.then(function (body) {
992-
expect(body).to.eql('POST /200'.length);
994+
expect(body).to.eql('POST /200 - {"some":"payload"}'.length);
993995
})
994996
.catch(function (err) {
995997
throw err;

0 commit comments

Comments
 (0)