Rabl、Jbuilder 还是手动 json 构建 API? [英] Rabl, Jbuilder or manual json build for api?

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

问题描述

要为大型应用程序构建 api,就性能而言,哪种方法更好,我应该使用 Rabl、Jbuilder 还是手动构建 json 对象?我正在为移动应用程序构建 api/endpoints.

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 通常更简单,更容易学习/使用,在这两种情况下都是 YMMV,但普遍的共识似乎是 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天全站免登陆