I'm still unsure if I should go with Grape in my Rails app or simply create a namespace and use ActionController::Metal + active_model_serializers to present my JSON. Could you guys tell me the big benefits of Grape mounted in rails instead of my other option? Not trying to start a war here, only looking for opinions (biased or not :P).Thanks!
--
You received this message because you are subscribed to the Google Groups "Grape Framework Discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ruby-grape+...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
dB. | Moscow - Geneva - Seattle - New York
dblock.org - @dblockdotorg
First, let me prefix all of this by saying that many people have built very successful APIs with Rails controllers.I did a talk about exactly this at NYC.rb a while ago, the slides are here: http://www.slideshare.net/dblockdotorg/building-restful-apis-w-grape. I have a somewhat updated view of things.I believe that Rails is very poorly suited for RESTful APIs because it does not speak the language of RESTful APIs. It speaks the language of MVC, instead. Rails does support APIs, but that is because it tries to be all things to everybody in a prescribed manner. Grape, on the other hand, is a tiny framework that tries to be nothing else than an API DSL.
- The words "router", "action" or "controller" are unnecessary abstractions.
- It's not clear where the API starts and ends. You can't say app/api is my API and everything is in there.
- Version 1 is easy, but version 2 is hard. It's difficult to maintain the matrix of routes to controllers when you're trying to do vendor-based content negotiation (Accept header).
- Testing an API via controller testing is insufficient because you need to test routes. But testing via requests makes tests asymmetrical to the API implementation.
- Everything is optimized for separating view, including, say caching. IMO the JSON representation of a resource is "just another view". That's why active_model_serializers actually exists and you can (and should) totally use that with Grape.
- Controllers encourage logic via functions, private methods, etc. They couple resource-based logic through full blown classes with pre/post filters. It only works if you keep them thin, but in practice it becomes a mess. Thick logic is very hard with Grape, you cannot share implementation between endpoints unless you abstract it away, forcing better code.
First thanks for your input! Bellow is my follow up:
On Wednesday, April 3, 2013 9:05:13 PM UTC-4, Daniel Doubrovkine wrote:First, let me prefix all of this by saying that many people have built very successful APIs with Rails controllers.I did a talk about exactly this at NYC.rb a while ago, the slides are here: http://www.slideshare.net/dblockdotorg/building-restful-apis-w-grape. I have a somewhat updated view of things.I believe that Rails is very poorly suited for RESTful APIs because it does not speak the language of RESTful APIs. It speaks the language of MVC, instead. Rails does support APIs, but that is because it tries to be all things to everybody in a prescribed manner. Grape, on the other hand, is a tiny framework that tries to be nothing else than an API DSL.
- The words "router", "action" or "controller" are unnecessary abstractions.
Agreed
- It's not clear where the API starts and ends. You can't say app/api is my API and everything is in there.
Agreed
- Version 1 is easy, but version 2 is hard. It's difficult to maintain the matrix of routes to controllers when you're trying to do vendor-based content negotiation (Accept header).
Does not https://github.com/bploetz/versionist or https://github.com/filtersquad/rocket_pants provide some techniques to do versioning?
- Testing an API via controller testing is insufficient because you need to test routes. But testing via requests makes tests asymmetrical to the API implementation.
What stop us from testing our api using controller tests using Rack::Test with get, post, put, delete methods? https://github.com/rubygems/rubygems.org/tree/master/test/functional/api/v1 does exactly this, you see something wrong with this technique? http://guides.rubyonrails.org/testing.html#functional-tests-for-your-controllers also use Rack::Test `get` in their own exemple. Requests specs in RSpec are the equivalent of integration tests, which rails define them as "Integration tests are used to test the interaction among any number of controllers".
- Everything is optimized for separating view, including, say caching. IMO the JSON representation of a resource is "just another view". That's why active_model_serializers actually exists and you can (and should) totally use that with Grape.
Oh I see, Entities are not part of grape by default now, and you're free to select what you want, good to know.
- Controllers encourage logic via functions, private methods, etc. They couple resource-based logic through full blown classes with pre/post filters. It only works if you keep them thin, but in practice it becomes a mess. Thick logic is very hard with Grape, you cannot share implementation between endpoints unless you abstract it away, forcing better code.
Agreed!
Hope this helps. I am happy to answer any questions.cheersdB.On Wed, Apr 3, 2013 at 3:44 PM, Mathieu Allaire <mathieu...@gmail.com> wrote:
I'm still unsure if I should go with Grape in my Rails app or simply create a namespace and use ActionController::Metal + active_model_serializers to present my JSON. Could you guys tell me the big benefits of Grape mounted in rails instead of my other option? Not trying to start a war here, only looking for opinions (biased or not :P).Thanks!--To unsubscribe from this group and stop receiving emails from it, send an email to ruby-grape+...@googlegroups.com.
You received this message because you are subscribed to the Google Groups "Grape Framework Discussion" group.--
You received this message because you are subscribed to the Google Groups "Grape Framework Discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ruby-grape+...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
You received this message because you are subscribed to a topic in the Google Groups "Grape Framework Discussion" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ruby-grape/Gh-vkqityZ8/unsubscribe?hl=en.
To unsubscribe from this group and all its topics, send an email to ruby-grape+...@googlegroups.com.