Charlie Davies
Charlie Davies

Reputation: 1834

Stripping rails down for api use only

I have an app that we are using just to serve api calls to another application. However it feels heavy as it is still using the whole of rails, but we don't use views etc...

How has other people tackled this issue, just remove the files ? All I need left is my modules and the ability to serve.

Would it be better to use Sinatra ?

Upvotes: 1

Views: 1195

Answers (3)

steve
steve

Reputation: 2008

Try taking a look at GRAPE which does exactly this - it's a little like Sinatra (uses Rack) but very lightweight and API focused. Webmachine is also pretty interesting (see http://code.dblock.org/grape-vs-webmachine for some comparisons)

Upvotes: 1

pepe
pepe

Reputation: 555

At my job we're doing exactly what you need. Unfortunately I'm not very familiar with the process of making it work, somebody else set it up. What I know is that in config/application.rb you can select the things you need for your app. You can even add/delete middleware if you need to. In case it helps in our case we are using these frameworks:

require "active_record/railtie"
require "action_controller/railtie"
require "action_mailer/railtie"
require "active_resource/railtie"

And removing these middlewares:

config.middleware.delete Rack::Lock
config.middleware.delete ActionDispatch::Flash
config.middleware.delete ActionDispatch::Cookies
config.middleware.delete ActionDispatch::Session::CookieStore
config.middleware.delete ActionDispatch::BestStandardsSupport

Upvotes: 2

Lars Haugseth
Lars Haugseth

Reputation: 14881

Check out the relatively new rails-api plugin, which offers a subset of Rails intended for building API services. You can read the release blog post here.

There's also a Railscasts episode demonstrating its use.

Upvotes: 5

Related Questions