#348 The Rails API Gem
It is often asked: Is Rails a good fit if I only need to serve an API? In this episode I show how to use the Rails API gem to create a slimmer Rails application designed to respond with JSON.
- Download:
- source code
- mp4
- m4v
- webm
- ogv
Thanks! But video quality is not usual :(
Yeah I also noticed the low quality in this video. Some codec related issue it seems.
Sorry, I can not see any benefit of this gem.
If you want to build an API, you really don't need the whole thing called Rails. But before stripping down Rails, think what Rails is. Rails is just a kind of collection of some ruby gems.
So it might be easier to use a more lightweight framework like padrino and put inside what you need.
See the video at 9:13.
actually, we can use
config.middleware.http_only!
to let rails run just for api because of removing middlware which not needed.Great Vid Ryan... I didn't notice any quality issues.
I am curious, would Authentication and Authorization work similar to a full rails application?
I like the idea of a Rails gem, but even after watching this and looking at the project. I'm still a fan of Grape.
Looks really nice :)
this looks awesome. how about an episode with Grape and OAuth2? +100
Great episode! I would love to see a screencast on how to build a OAuth2 protected API with that ;)
+1
And versioning!
yep!
+1
+1
+1
+1
+1 for a redo of this episode showing API versioning and OAuth2. If you're focusing on providing an API, the view stuff is orthogonal.
Also, some context on perf would be very useful here.
+1
+1
+1!
+1
How does this stack up Padrino? As far as performance and ease-of-use?
Just saw that you're using rbenv. I have been thinking of switching from rvm for a while now, but a Railscast on the subject would definitely get me to actually do it. Please do one!
+1
What I like in this gem is
ActionController::API
which is a bit lighter thanActionController::Base
.What I don't like in this gem is everything else.
If you want to create an API application with some HTML admin panel, you either need to use "normal" Rails and rely on
ActionController::Base
, possibly stripping it somehow, or use "rails-api", but reenable nearly everything. Both approaches suck. Too bad spastorino haven't decided to includeActionController::API
in Rails (or maybe that was impossible) and make "rails-api" nothing more than configuration generator.I prefer to use Grape mounted in routes, so I get nice DSL behind decent Rails middleware.
Is the asset pipeline available if you use the defaults from rails-api? I want to use rails for backend REST but ember.js for the frontend and include it as part of my js assets.
awesome
what about Grape ?
getting it more interesting
Indeed
How can I integrate Unfuddle API ??? Will you please give some idea.
for those having 'undefined' tasks on the list in their example, change the addtask function to the following:
function addTask(line) {
$('#tasks').append('' + line.task.name + '');
}
Thanks! This worked, though still don't understand why.
This blog post compares Grape and rails-api performance: http://blog.backupify.com/2013/09/30/a-framework-comparison-of-grape-vs-railsapi-part-1-performance/