2016-11-29 5 views
0

.then()のhttpポストをしたいと思います。私はすでに多くの方法でそれをしてきました...何も働かなかった 私はユーザーを作成しようとしていると、http POSTの作成後にします。http post inside .then()

'use strict'; 

module.exports = function(app) { 
return function(req, res, next) { 
const body = req.body; 

// Get the user service and `create` a new user 
app.service('users').create({ 
    email: body.email, 
    password: body.password 
}).then('I WANT HTTP POST WITH PARAMS HERE') 
// On errors, just call our error middleware 
.catch(next); 

}; 
}; 

私はあなたが約束チェーンの約束を返すことができPOST

答えて

2

にメールアドレスとパスワードを送信します。ここではpostAsyncを実行するための約束されたリクエストを使用します。

var Promise = require('bluebird') 
var request = Promise.promisifyAll(require('request')) 

app.service('users').create({ 
     email: body.email, 
     password: body.password 
    }).then(function(createUserResp) { 
     return request.postAsync(/**/) 
    }) 
    }).then(function(resp) { 
     // do sth 
    }) 
    .catch(next); 
0
var RP = require('request-promise') 

app.service('users').create({ 
    email: body.email, 
    password: body.password 
}).then(function() { 
    var opt = { 
     url: 'targetUrl', 
     formData: { 
      email: body.email, 
      password: body.password 
      //, json: true // if result is in json format 
     } 
    } 
    return RP.post(opt) 
}).then(function (postResult) { 

}) 
.catch(next);