Comments (11)
Hi @FredericHeem Request-Promise has the exact same API as Request. Only that you can now use promises instead of callbacks. In particular it means you can use alls options Request provides as well:
rp({
uri : 'http://posttestserver.com/post.php',
method : 'POST',
qs: {
name: 'some name',
email: '[email protected]'
}
})
.then(function (body) {
// ...
});
Or even the shorthand Request provides:
rp.post({
uri : 'http://posttestserver.com/post.php',
qs: {
name: 'some name',
email: '[email protected]'
}
})
.then(function (body) {
// ...
});
Is that what you were looking for or did I miss your point?
from request-promise.
I meant post parameter in the body, not as a query string, FYI, this is the function that is supposed to be ported to request-promise:
Client.prototype._ops = function(ops, action, resCodes, param) {
var me = this;
var deferred = Q.defer();
var data = updateRequestWithKey(this, {});
if(param){
data.json = param;
}
data.method = ops;
request(this.url + action, data, function(err, res, body) {
if (err) {
return deferred.reject(err)
}
if (resCodes.indexOf(res.statusCode) == -1){
return deferred.reject(bodyToError(body))
} else {
deferred.resolve(body);
}
})
return deferred.promise;
}
In the meantime, using Promise.promisify(request) solves the issue.
from request-promise.
Oh, interesting. I didn't know of the possibility to pass the data as the second parameter. Is this somewhere documented? I looked through Request's whole README and didn't find it.
Could you give me an actual data object I can use for writing a test?
from request-promise.
I just made the following test which is successful:
it('for passing the data as second parameter', function (done) {
rp('http://localhost:4000/200', { method: 'POST' })
.then(function (body) {
expect(body).to.eql('POST /200');
done();
})
.catch(done);
});
Does this reproduce your scenario?
from request-promise.
Do you mind to try this ?
it('for passing the data as second parameter with data', function (done) {
rp('http://localhost:4000/200', { method: 'POST', data: { json : {foo:"bar"}} })
.then(function (body) {
expect(body).to.eql('POST /200');
done();
})
.catch(done);
});
from request-promise.
This one is successful:
it('for passing the data as the second parameter', function (done) {
rp('http://localhost:4000/200', { method: 'POST', json: { foo: 'bar' } })
.then(function (body) {
expect(body).to.eql('POST /200 - {"foo":"bar"}');
done();
})
.catch(done);
});
I had to change data: { json : {foo:"bar"}}
to just json: { foo: 'bar' }
. Anyway, I tested the same with plain Request and there it behaved exactly the same.
BTW, in theory any use case that works with plain Request should work with Request-Promise as well because Request-Promise is not a wrapper. It exposes the actual Request object. Anyway, that is just theory and now I wonder why your code is not working. Any ideas?
from request-promise.
Hi @FredericHeem did you find the cause or can I help you somehow finding it?
from request-promise.
For the time being, I sticked with Promise.promisify(request).
Thanks for your support
from request-promise.
Btw, what's the difference between bluebird.promisify(request)
and request-promise
?
from request-promise.
Hi @fritx Request-Promise is of course better tailored towards how Request is used. In particular, the simple
option better devides which responses go to .then(...)
and which responses go to .catch(...)
. Overall the requests can be written in a cleaner way.
from request-promise.
Thanks for explanation!
from request-promise.
Related Issues (20)
- Proper way to do retry logic
- How to transform response headers?
- Produces warning for jest 25.5.0
- Uploading file with metadata using unirest js api causing trouble when sending data
- How to curl --http 1.0 in request-promise
- 如何请求图片,返回的数据如何处理呢 HOT 1
- Hey @pradiptabasu , you need to install `request` yourself before you install `request-promise`. See the [installation instructions](https://github.com/request/request-promise#installation).
- error message RequestError: Error: Invalid URI "xxxxxxxx",how to deal it?
- Error: Client network socket disconnected before secure TLS connection was established HOT 3
- Including this library will drag a ton of deps/files... sad
- Error: EPERM: operation not permitted, read
- Terminal
- read timeout
- How to see the request of a failed request ? HOT 3
- WeChat Mini Program can't support 'promise' grammar
- requestpromise
- ignore proxy signed certificate(ssl) issue in request-promise HOT 1
- The "request" library is not installed automatically anymore.
- Request/request-promise
- Issue on a dependency - CVE-2023-26136 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from request-promise.