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

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

问题描述

我有一个应用程序,其主要功能是通过websockets或长轮询实时工作。

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

但是,大部分网站都是以RESTful方式编写的,适用于未来的应用程序和其他客户端。但是,我正在考虑转换到所有站点功能的websocket API,远离REST。这样我就可以更轻松地将实时功能集成到网站的所有部分。这会使构建应用程序或移动客户端变得更加困难吗?

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.

我的计划是使用 DNode SocketIO Backbone 。使用这些工具,我的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.

使用Socket.IO和Express的好教程。它向socket.io公开了快速会话,并讨论了如何为每个经过身份验证的用户提供不同的房间。

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.

  • http://www.danielbaulig.de/socket-ioexpress/

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

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

  • http://fzysqr.com/2011/02/28/nodechat-js-using-node-js-backbone-js-socket-io-and-redis-to-make-a-real-time-chat-app/
  • http://fzysqr.com/2011/03/27/nodechat-js-continued-authentication-profiles-ponies-and-a-meaner-socket-io/

教程使用设g使用Backbone.js的Pusher(使用Rails):

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

  • http://blog.pusher.com/2011/6/21/backbone-js-now-realtime-with-pusher

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

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

  • http://andyet.net/blog/2011/feb/15/re-using-backbonejs-models-on-the-server-with-node/
  • http://addyosmani.com/blog/building-spas-jquerys-best-friends/
  • http://fzysqr.com/2011/02/28/nodechat-js-using-node-js-backbone-js-socket-io-and-redis-to-make-a-real-time-chat-app/
  • http://fzysqr.com/2011/03/27/nodechat-js-continued-authentication-profiles-ponies-and-a-meaner-socket-io/

使用带有DNode的Backbone:

Using Backbone with DNode:

  • http://quickleft.com/blog/backbone-without-ajax-part-ii
  • http://quickleft.com/blog/backbone-without-ajax-part-1
  • http://sorensen.posterous.com/introducing-backbone-redis
  • https://github.com/cowboyrushforth/minespotter
  • http://amir.unoc.net/how-to-share-backbonejs-models-with-nodejs
  • http://hackerne.ws/item?id=2222935
  • http://substack.net/posts/24ab8c

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

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