独立REST API JSON服务器和客户端? [英] Separate REST JSON API server and client?

查看:122
本文介绍了独立REST API JSON服务器和客户端?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要从头开始创建一批网络应用程序。 (请参见 http://50pop.com/$c$c 获得概述。)我想为他们能必须从许多不同的客户端访问:前端网站,智能手机应用程序,Web服务的后端,等等。所以我真的想为每一个JSON REST API

另外,我preFER在后台工作,所以我遐想我保持纯粹的API我的重点,并雇用别人来使前端用户界面,无论是网站,iPhone,Android的,或其他应用程序。

请帮我决定哪些方法,我应该采取:


  

一起钢轨


  
  

请了非常标准的Rails Web的应用程序。在控制器中,执行respond_with开关,以服务JSON或HTML。 JSON响应是那么我的API。


  
  

临: precedent大量的。伟大的标准和安培;做事这样的例子很多。


  
  

缺点:不一定要API是相同的Web应用程序。不喜欢的if / then respond_with开关的方法。混合两种不同的事物(UI + API)。



  

REST服务器+ JavaScript的重CLIENT


  
  

请仅JSON的REST API服务器。使用骨干或Ember.js对客户端JavaScript直接访问API,在浏览器中显示的模板。


  
  

临:我爱API和放大器的分离;客户。聪明的人说这是要走的路。伟大的理论。似乎尖端和令人兴奋的。


  
  

缺点:不多precedent。这样的例子并不多做得很好。公共实例(twitter.com)感觉迟钝和放大器;甚至从这种方法中切换了。



  

REST服务器+服务器端HTML客户


  
  

请仅JSON的REST API服务器。做一个基本的HTML网站的客户端,只访问REST API。少客户端JavaScript。


  
  

临:我爱API和放大器的分离;客户。但是,供应纯HTML5是相当万无一失&安培;没有客户密集的。


  
  

缺点:不多precedent。这样的例子并不多做得很好。框架不支持这一点。不知道如何处理它。


特别是寻找来自体验,而不仅仅是在理论上的建议。


解决方案

目前大千世界,我们已经走了深深的使用选项#2和它卷起到成千上万的学生。我们的服务器是一个JSON REST API(斯卡拉+ MongoDB的),以及所有我们的客户code的供应直出CloudFront的的。(如:www.boundless.com仅仅是CloudFront的一个别名)

优点:


  • 尖端/激动人心

  • 有很多爆炸为您的降压的:API为您提供了自己的Web客户端,移动客户端,第三方接入等基础

  • 非常的现场快速装载/网页过渡

缺点:


  • 不是搜索引擎友好/没有准备很多工作。

  • 需要一流的Web前端民间谁愿意应付瓦特/的现场经验的现实,70%的JavaScript,这意味着什么。

我认为这是所有网络应用的未来。

的几点思考为Web前端人(这是所有新的烦躁/挑战是有这个架构):


  • CoffeeScript的。更容易生产出高品质的code。

  • 骨干。伟大的方式来组织你的逻辑,活跃的社区。
  • HAMLC。 HAML + CoffeeScript的模板=> JS。

  • 上海社会科学院

我们已经建立了所谓的晶石(单页应用飞船)为我们的前端开发的一具有效地从滑轨资产管道调整为单个页面应用程序开发。我们将在接下来的几个对我们的 github上页面星期内开放式采购,以博客文章,解释如何使用它和整体沿结构更详细地

更新:

对于人们的关注与骨干,我觉得他们高估的。骨干远远超过它是一种深深的框架的组织原则。 Twitter的网站本身就是JavaScript的一个巨型兽覆盖整个数百万用户和放大器的每一个角落情况;传统的浏览器,同时加载微博实时,垃圾收集,显示大量的多媒体,等所有的纯JS我见过的网站中,Twitter是一样与众不同。已经有许多IM pressively通过JS交付复杂的应用程序,票价非常好。

和体系结构的选择完全取决于你的目标。如果您正在寻找支持多个客户端,并已获得良好的前端人才最快的方式,在一个独立的API的投资是一个伟大的路要走。

I'm about to create a bunch of web apps from scratch. (See http://50pop.com/code for overview.) I'd like for them to be able to be accessed from many different clients: front-end websites, smartphone apps, backend webservices, etc. So I really want a JSON REST API for each one.

Also, I prefer working on the back-end, so I daydream of me keeping my focus purely on the API, and hiring someone else to make the front-end UI, whether a website, iPhone, Android, or other app.

Please help me decide which approach I should take:

TOGETHER IN RAILS

Make a very standard Rails web-app. In the controller, do the respond_with switch, to serve either JSON or HTML. The JSON response is then my API.

Pro: Lots of precedent. Great standards & many examples of doing things this way.

Con: Don't necessarily want API to be same as web app. Don't like if/then respond_with switch approach. Mixing two very different things (UI + API).

REST SERVER + JAVASCRIPT-HEAVY CLIENT

Make a JSON-only REST API server. Use Backbone or Ember.js for client-side JavaScript to access API directly, displaying templates in browser.

Pro: I love the separation of API & client. Smart people say this is the way to go. Great in theory. Seems cutting-edge and exciting.

Con: Not much precedent. Not many examples of this done well. Public examples (twitter.com) feel sluggish & are even switching away from this approach.

REST SERVER + SERVER-SIDE HTML CLIENT

Make a JSON-only REST API server. Make a basic HTML website client, that accesses the REST API only. Less client-side JavaScript.

Pro: I love the separation of API & client. But serving plain HTML5 is quite foolproof & not client-intensive.

Con: Not much precedent. Not many examples of this done well. Frameworks don't support this as well. Not sure how to approach it.

Especially looking for advice from experience, not just in-theory.

解决方案

At Boundless, we've gone deep with option #2 and rolled it out to thousands of students. Our server is a JSON REST API (Scala + MongoDB), and all of our client code is served straight out of CloudFront (ie: www.boundless.com is just an alias for CloudFront).

Pros:

  • Cutting-edge/exciting
  • A lot of bang for your buck: API gives you basis for your own web client, mobile clients, 3rd party access, etc.
  • exceedingly fast site loading / page transitions

Cons:

  • Not SEO friendly/ready without a lot more work.
  • Requires top-notch web front-end folk who are ready to cope w/ the reality of a site experience that is 70% javascript and what that means.

I do think this is the future of all web-apps.

Some thoughts for the web front end folks (which is where all the new-ness/challenge is given this architecture):

  • CoffeeScript. Much easier to produce high-quality code.
  • Backbone. Great way to organize your logic, and active community.
  • HAMLC. Haml + CoffeeScript templates => JS.
  • SASS

We've built a harness for our front-end development called 'Spar' (Single Page App Rocketship) which is effectively the asset pipeline from Rails tuned for single page app development. We'll be open-sourcing within the next couple of weeks on our github page, along with a blog post explaining how to use it and overall architecture in greater detail.

UPDATE:

With respect to people's concerns with Backbone, I think they are over-rated. Backbone is far more an organizational principle than it is a deep framework. Twitter's site itself is a giant beast of Javascript covering every corner-case across millions of users & legacy browsers, while loading tweets real-time, garbage collect, display lots of multimedia, etc. Of all the 'pure' js sites I've seen, Twitter is the odd one out. There have been many impressively complicated apps delivered via JS that fare very well.

And your choice of architecture depends entirely on your goals. If you are looking for the fastest way to support multiple clients and have access to good front-end talent, investing in a standalone API is a great way to go.

这篇关于独立REST API JSON服务器和客户端?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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