【发布时间】:2021-04-19 07:08:55
【问题描述】:
我遇到了需要在 node.js 中调用嵌套 REST api 的情况 当我收到路由休息 api POST 调用时, 然后在 POST(parent) 期间需要在 POST 调用中调用 REST get call(child)。
我这样做是为了将父数据与子数据合并,然后将其存储在 MongoDB 中
这是一个例子..(routes/index.js)
const variable = require('../app.js');
const { db } = require('../models/user.js');
const async = require('async');
const time_js = require('../time.js');
module.exports = function (app, Transaction_log, User) {
app.post('/api/transaction_logs', function (req, res) {
... get method REST call to certain url(different IP addr) with header option
}
}
不知道
- 如何调用 REST API get call inside with header option(x-api-key sting)
- 将获取返回的数据与插入后的数据合并到一个对象中
有没有办法做到这一点?
【问题讨论】:
-
你没有在那里声明
app。我猜这是一个 Express 应用程序 -
@Reger 对不起,我没听懂。我有 app.js 并在那里声明了 app。 :S 是的,它是 var app = express();使用 express 框架
-
这里的挑战是什么?
-
@Qausim 不知道如何调用 REST API get call inside with header option(x-api-key sting)
标签: javascript node.js express mongoose rest