我想使用 Request-Promise NodeJs 模块将从一个 API 收到的响应作为请求参数传递到另一个 API 中。有人可以帮我吗?我简要介绍了下面的示例代码:
var Sequence = {
test1: function (param) {
return request({
"method": "POST",
"uri": baseURL+"/v1/" + userID + "/test/info/",
"json": true,
"headers": {
"Accept": "application/json",
},
}).then(function (result) {
return result.pairingInfo // I want to use this pairinfInfo param in another request
})
test2 : function (param) {
return request({
"method": "POST",
"uri": baseURL+"/v1/passenger/" + userID + "/test/test/",
"json": true,
"headers": {
"Accept": "application/json",
},
"qs": {
**"pairingInfo": pairingInfo**,//This pairingInfo would come from the returned result.pairingInfo of test 1 API call
}
})
}
},
How can I achieve this?
最佳答案
您可以使用 this
,因为 test1()
方法中有一个 return
语句。因此,只需触发它即可获取它:
"qs": {
"pairingInfo": this.test1(),
}
关于javascript - 如何使用 Request-Promise 将一个 API 的响应作为请求参数传递到另一个 API 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52661464/