基于REST的API或Socket.IO [英] RESTful Api or Socket.IO

查看:553
本文介绍了基于REST的API或Socket.IO的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写一个移动应用程序。它连接到服务器的Node.js和获取一些数据。
这是从服务器的NodeJS检索数据的最佳方式?

Im writing a mobile application. It connects to the node.js server and getting some data. Which is the best way to retrieving data from nodejs server?

我的项目架构:

MySQL数据库< - > Node.js的(服务器)LT; - (socket.io或宁静) - >移动客户端

mySQL DB <-> node.js (Server) <--(socket.io or restful)--> mobile clients

推荐答案

如果您需要服务器和客户端之间的双向实时连接(如聊天机器人或股票),然后socket.io将是一个不错的选择。

If you need a bidirectional real-time connection between your server and your client (e.g. a chat bot or a stock ticker), then socket.io would be a good choice.

不过,如果你只需要不时从服务器获取一些数据的时间在客户端(和/或推一些数据),那么一个RESTful架构更有意义。

However if you just need to fetch some data from time to time on the client from the server (and / or push some data), then a RESTful architecture makes more sense.

对于大多数使用案例的RESTful架构可能是更好的。如果您阐述详细了解一下你的客户端和服务器之间共享什么样的数据,有可能是一个更precise答案。

For most use cases a RESTful architecture is probably better. If you elaborate a bit more about what kind of data you're sharing between the client and the server, there could be a more precise answer.

这篇关于基于REST的API或Socket.IO的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆