Rabl, Jbuilder or manual json build for api?
Asked Answered
T

2

8

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.

Tetryl answered 24/9, 2012 at 19:23 Comment(0)
C
17

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 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 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'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.

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

Chemosphere answered 22/2, 2013 at 0:55 Comment(3)
Having used JBuilder a lot more than RABL, I should make it clear that I'm also slightly biased towards it.Chemosphere
Since I have a very basic API, would it be bad if I just used an application_controller.rb with a custom route for each API call?Backgammon
Bad? Well, it wouldn't be RESTful, and would (probably) go against object oriented design principles / SOLID en.m.wikipedia.org/wiki/SOLID_(object-oriented_design). I'd tend to suggest that you consider that nothing ends up staying small if you actually use it, so it's worth not being too lazy up front, so that you can stay a bit lazy (or at least less stressed) in the future, when you need to extend the project, which often happens, even if it wasn't planned originally.Chemosphere
S
0

I suggests Jbuilder. Because Jbuilder has core development of Rails. So at the time of upgradation it may not create problem.

Semite answered 6/12, 2013 at 12:28 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.