Rabl的,在Jbuilder或手动JSON建立API? [英] Rabl, Jbuilder or manual json build for api?

查看:143
本文介绍了Rabl的,在Jbuilder或手动JSON建立API?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

要为大型应用程序,它的方法是interms性能更好的打造API,我应该使用Rabl的,在Jbuilder或手动构建JSON对象?我建立API /端点移动应用。

To build api for a large scale application, which method is better interms of performance, should i use Rabl, Jbuilder or build json objects manually?I am building api /endpoints for mobile apps.

推荐答案

在性能方面,你应该尝试建立一些基本的性能测试,并对他们的个人资料。

In terms of performance, you should try creating some basic performance tests, and profile them.

假设你的应用程序的模型关联的最复杂的部分是最薄弱的点在响应能力和设计围绕您的测试。

Assume the most complicated part of your application's model associations is your weakest point in terms of responsiveness and design your test around that.

一般来说有你应该考虑到一些其他的东西。

Generally speaking there are a few other things you should take into consideration.


  • as_json 覆盖会很快失控在你的模型,并成为您的应用程序的脆性一部分。许多人认为的API作为一个视图,因此它的逻辑应该分开从模式走,保持灵活性/互换和测试。这既是的JBuilder和Rabl的主要优势。最终甚至与 as_json 建立了一个简单的JSON API将成为乞讨重构时,他们需要进行扩展,因此它使用的是DSL可能是值得学习的初始复杂性/。这就是说,当然也有一些情况下,这是完全确定使用 as_json 你只需要知道的可扩展性和维护问题。

  • as_json overrides will quickly get out of hand in your models, and become a brittle part of your application. Many people consider an API as a view, and therefore the logic for it should be separated away from the Model, to remain flexible/interchangeable and testable. This is the main advantage of both JBuilder and RABL. Ultimately even a simple JSON api built with as_json will be begging for refactoring when they need to be extended, so it's probably worth the initial complexity of learning/using a DSL. That said, there are certainly some cases where it's perfectly ok to use as_json you just need to be aware of problems with scalability and maintenance.

在Jbuilder曾经有过的表现相当差,但是这是因为关于这个问题,首先发布的同时深深的提高。在此之前,Rabl的是方式更好的性能。在这一点上,在Jbuilder是触摸更快

Jbuilder used to have quite poor performance, however this was deeply improved about the same time as this question was first posted. Before that RABL was way more performant. At this point, Jbuilder is a touch faster.

Rabl的的DSL通常比在Jbuilder的少的青睐,它可以在起步困难,并在以后的维护。在Jbuilder的DSL是一般来说,简单,更容易学习/使用,在这两种情况因人而异,但普遍的共识似乎是,在Jbuilder是比较容易拾起并运行。

RABL's DSL is generally less favored than Jbuilder's, it can be a difficulty in getting started, and in later maintenance. Jbuilder's DSL is generally speaking, simpler and easier to learn/use, in both cases YMMV, but the general consensus appears to be that Jbuilder is easier to pick up and run with.

由于这个问题是5个月大,对不起,我没看出来得越早,我期望的决定早已作出的。

Since this question is 5 months old, sorry I didn't see it sooner, I expect the decision has long ago been made.

这篇关于Rabl的,在Jbuilder或手动JSON建立API?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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