简体   繁体   English

从 Nodejs 发送数据 API 到 Flask APi

[英]Send data from Nodejs API to Flask APi

so i am creating a small application in Nodejs and Flask.所以我在 Nodejs 和 Flask 中创建了一个小应用程序。 I have created 2 apis.我创建了 2 个 API。 First one sending data from Nodejs App to Nodejs API then sending the data from the Nodejs API to flask api.第一个从 Nodejs 应用程序发送数据到 Nodejs API 然后将数据从 Nodejs API 发送到 flaskZ8A5DA59AAZ7C319C3206A7F10C17C3B9116D4A957646Z1A78AAZ7D10574E。 I am having a bit of trouble sending the data from the Node Api to the Flask Api.我在将数据从节点 Api 发送到 Flask Api 时遇到了一些麻烦。

//send data from Node.js api to Flask Api //从Node.js api发送数据到Flask Z72664DC0959F3B0C048391F8C7046A

app.get('/postoflask',  (req, res) => {
 request('http://localhost:3030/users',  (error, response, bodyParser) => {
      if(error) {
          
          res.send(' erorr occured')
      }
  
      else {
          res.send(bodyParser)
          request.post('http://localhost:5000/adduser')
        }
  });
});

Deploying the route on the browser retrieves the data from the node Api database and pushes null values to the flask api database. Deploying the route on the browser retrieves the data from the node Api database and pushes null values to the flask api database. i need the data retrieved from the Node Api to be transferred as it is to the database of the flask database.我需要将从节点 Api 检索到的数据原样传输到 flask 数据库的数据库中。

port 3030/users is the node api that fetches data from database and port 5000/adduser is flask api to push data into database.端口 3030/users 是从数据库中获取数据的节点 api,端口 5000/adduser 是 flask api 将数据推送到数据库中。

I am an entry to mid-level programmer, but i don't know what i am missing here or what i am not understanding.我是中级程序员的入门,但我不知道我在这里缺少什么或我不理解什么。 Help will be very appreciated.帮助将不胜感激。 Database used is PostgreSql.使用的数据库是 PostgreSql。

You can leverage request stream capabilities in order to proxy data from Node.js endpoint to Flask:您可以利用请求 stream 功能将数据从 Node.js 端点代理到 Flask:

app.get('/postoflask', (req, res) => {
  request('http://localhost:3030/users')
    .on('error', (err) => {
      console.log(err);
    })
    .on('end', () => {
      res.send('done')
    })
    .pipe(request.post('http://localhost:5000/adduser'));
})

You're not sending any data in request.post('http://localhost:5000/adduser') , try您没有在request.post('http://localhost:5000/adduser')中发送任何数据,请尝试

request.post('http://localhost:5000/adduser',{...})

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM