Websocket API 取代 REST API? [英] Websocket API to replace REST API?

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

问题描述

我有一个应用程序,其主要功能通过 websockets 或长轮询实时运行.

I have an application whose primary function works in real time, through websockets or long polling.

然而,该站点的大部分内容都是以 RESTful 方式编写的,这对未来的应用程序和其他客户端非常有用.但是,我正在考虑从 REST 过渡到所有站点功能的 websocket API.这将使我更容易将实时功能集成到网站的所有部分.这是否会使构建应用程序或移动客户端变得更加困难?

However, most of the site is written in a RESTful fashion, which is nice for application s and other clients in the future. However, I'm thinking about transitioning to a websocket API for all site functions, away from REST. That would make it easier for me to integrate real time features into all parts of the site. Would this make it more difficult to build applications or mobile clients?

我发现有些人已经在做这样的事情:SocketStream

I found that some people are already doing stuff like this: SocketStream

推荐答案

并不是说这里的其他答案没有价值,他们提出了一些很好的观点.但我将与普遍共识背道而驰并同意你的观点,即转向 websockets 不仅仅是为了实时功能,这非常有吸引力.

Not to say that the other answers here don't have merit, they make some good points. But I'm going to go against the general consensus and agree with you that moving to websockets for more than just realtime features is very appealing.

我正在认真考虑通过 websockets 将我的应用程序从 RESTful 架构转移到更多的 RPC 风格.这不是一个玩具应用程序",我不只是在谈论实时功能,所以我有保留.但我看到了走这条路的许多好处,并认为它可能会成为一个特殊的解决方案.

I am seriously considering moving my app from a RESTful architecture to more of an RPC style via websockets. This is not a "toy app", and I'm not talking about only realtime features, so I do have reservations. But I see many benefits in going this route and feel it could turn out to be an exceptional solution.

我的计划是使用 DNodeSocketIO主干.使用这些工具,我的 Backbone 模型和集合可以通过简单地调用 RPC 样式的函数从/向客户端和服务器传递.不再需要管理 REST 端点、序列化/反序列化对象等.我还没有使用过 socketstream,但看起来值得一试.

My plan is to use DNode, SocketIO, and Backbone. With these tools, my Backbone models and collections can be passed around from/to client and server by simply calling a functions RPC-style. No more managing REST endpoints, serializing/deserializing objects, and so forth. I haven't worked with socketstream yet, but it looks worth checking out.

在我可以肯定地说这是一个很好的解决方案之前,我还有很长的路要走,而且我确信它不是适用于每个应用程序的最佳解决方案,但我相信这种组合会非常强大.我承认有一些缺点,比如失去缓存资源的能力.但我有一种感觉,优势会超过它们.

I still have a long way to go before I can definitively say this is a good solution, and I'm sure it isn't the best solution for every application, but I'm convinced that this combination would be exceptionally powerful. I admit that there are some drawbacks, such as losing the ability to cache resources. But I have a feeling the advantages will outweigh them.

我有兴趣关注您探索此类解决方案的进展.如果你有任何 github 实验,请指点我.我还没有,但希望很快.

I'd be interested in following your progress exploring this type of solution. If you have any github experiments, please point me at them. I don't have any yet, but hope to soon.

下面是我一直在收集的稍后阅读链接的列表.我不能保证它们都是值得的,因为我只是略读了其中的许多.但希望有些人会有所帮助.

Below is a list of to-read-later links that I've been collecting. I can't vouch that they are all worthwhile, as I've only skimmed many of them. But hopefully some will help.

关于在 Express 中使用 Socket.IO 的很棒的教程.它向 socket.io 公开了 express 会话,并讨论了如何为每个经过身份验证的用户提供不同的房间.

Great tutorial on using Socket.IO with Express. It exposes express sessions to socket.io and discusses how to have different rooms for each authenticated user.

关于 node.js/socket.io/backbone.js/express/connect/jade/redis 的教程,包括身份验证、Joyent 托管等:

Tutorial on node.js/socket.io/backbone.js/express/connect/jade/redis with authentication, Joyent hosting, etc:

在 Backbone.js 中使用 Pusher 的教程(使用 Rails):

Tutorial on using Pusher with Backbone.js (using Rails):

在客户端使用backbone.js构建应用程序,在服务器使用node.js使用express、socket.io、dnode构建应用程序.

Build application with backbone.js on the client and node.js with express, socket.io, dnode on the server.

在 DNode 中使用 Backbone:

Using Backbone with DNode:

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

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