简体   繁体   English

将新数据从Node REST API推送到React-Native

[英]Push new data from Node REST API to React-Native

Problem 问题

I've created a REST API using Node and a client app using React-Native. 我已经使用Node创建了一个REST API,并使用React-Native创建了一个客户端应用。

So far I've configured it so the client app makes HTTP requests to the server. 到目前为止,我已经对其进行了配置,以便客户端应用向服务器发出HTTP请求。

Now I need to push new data from the server to the client as soon as it is available. 现在,我需要尽快将新数据从服务器推送到客户端。 I need to push different data to the client app depending on which user is logged in. 我需要根据登录的用户将不同的数据推送到客户端应用程序。

I haven't done this before and I've been having trouble finding a good solution online, partially because I don't know the correct terminology. 我以前没有做过,而且在网上很难找到一个好的解决方案,部分原因是我不知道正确的术语。

The server will pull the data from an external API, save it to MongoDB via Mongoose. 服务器将从外部API中提取数据,并通过Mongoose将其保存到MongoDB。 I then need to push the new data to the client 然后,我需要将新数据推送到客户端

If anyone has any suggestions that would be great! 如果有人有任何建议,那就太好了!

Environment 环境

Node.js with Express v4.16.4 React-Native v0.58.0-rc.2 Mongoose v5.4.5 带有Express v4.16.4的Node.js React-Native v0.58.0-rc.2猫鼬v5.4.5

Firebase is already installed in the react-native app. Firebase已安装在react-native应用程序中。 I'm proficient with both Mongoose and Firebase so either one could be good for the push queue if applicable. 我对Mongoose和Firebase都很精通,因此如果适用的话,任一个对于推送队列都可能很好。

Thanks! 谢谢!

1. can use socket.io 1.可以使用socket.io
Server send data to client using Web socket(socket.io). 服务器使用Web套接字(socket.io)将数据发送到客户端。

2. can use firebase push notification. 2.可以使用firebase推送通知。
Server can create new notification to firebase, and client can received signal from firebase, and get data from server via REST api. 服务器可以向Firebase创建新的通知,客户端可以从Firebase接收信号,并通过REST API从服务器获取数据。

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

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