What are the benefits of using Grape in the Rails app?

651 views
Skip to first unread message

Tomáš Linhart

unread,
Feb 20, 2013, 6:11:57 PM2/20/13
to ruby-...@googlegroups.com

I have a Rails web app and I want to provide API. I have found Grape and it looked nice and it can also be mounted into Rails but I am not sure of benefits of mounting Grape into my Rails app and use it for API instead of Rails controllers.

As I understand Grape is great for building applications that provide only API but it is not my case.

What do you think are the benefits of using Grape in the Rails app and why should I do so?

Daniel Doubrovkine

unread,
Feb 20, 2013, 6:28:10 PM2/20/13
to ruby-...@googlegroups.com
I did a talk at NYC.rb about Grape a while ago, http://www.slideshare.net/dblockdotorg/building-restful-apis-w-grape.

I think slide 5 describes why I think Rails is a poor fit for a RESTful API. The gist is that an MVC is probably the worst fit for a RESTful API. What's a controller in an API? What's a view? Sure, you can bend rails to do a RESTful API, but you will lose your sanity before the separation of concerns.

A RESTful API is something that is very close to the HTTP protocol. I know of two good approaches, Sinatra and WebMachine. Grape is basically Sinatra, with a lot more API-specific constructs (eg. versioned content negotiation or automatic JSON and XML formatting). Webmachine is very resource-declaration-intensive, which is also awesome (you can read about it in http://code.dblock.org/grape-vs-webmachine).

Hope this helps.

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

Ziyan Junaideen

unread,
Nov 6, 2015, 2:23:09 AM11/6/15
to Grape Framework Discussion
I don't think I can agree with Daniels answer completely. But how ever he has a point. Here is what I think and its based on my current understanding of my interest to implement an API.

We have an Rails app and that app should provide a JSON API for a mobile app to consume. I landed up on a Rails Cast that described how to use normal namespaced controllers to handle the task. But then I saw Grape. It doesn't seem to significantly simplify life.

But the thing is, Rails is a little bulky for an API. I one day might want to move the app to Sinatra. So that day, having an API defined with Grape might make a transition a little easy. But if you are not thinking of a transition, I think it gives a big reason to go with it.

Correct me if I am wrong.

Daniel Doubrovkine

unread,
Nov 6, 2015, 9:21:02 AM11/6/15
to ruby-...@googlegroups.com
I think by removing the need for Rails, Grape significantly simplifies life. You can have an API like https://github.com/ruby-grape/grape-on-rack that IMO is much cleaner. In many ways Grape and Sinatra aver synonymous except one focuses on serving an API and the other on serving web content. 

--
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/d/optout.



--

Reply all
Reply to author
Forward
0 new messages