Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Possible to API-ify namespace only? #209

Open
brianlittmann opened this issue Oct 27, 2015 · 4 comments
Open

Possible to API-ify namespace only? #209

brianlittmann opened this issue Oct 27, 2015 · 4 comments

Comments

@brianlittmann
Copy link

I've been doing a bit of reading on approaches to this, but nothing really stood out. It's a pretty common setup:

  • Rails API (for iOS or other clients)
  • Admin area (desktop interface)
  • Possibly a few web views for basic things like reset password

The simplest approach is just a single app with different namespaces for each, but with that comes all of the default Rails middleware on the API side even if its controllers inherit from ActionController::API, right?

If you want to use the Rails default middleware stack (avoid the reduction that rails-api does), you can just add config.api_only = false to config/application.rb file.

So is it possible to have a custom application.rb and conditionally load certain middleware on the api/ namespace only? Or is it an all or none thing, where I either use an engine for my main app code and share it across multiple Rails apps (one for the admin, one for the API) or wrap all the namespaces under one big red bow and have an API operating under a full/default Rails stack (regarding middleware, not controller modules)?

@tagrudev
Copy link

I was thinking the same, is there a possibility to use rails-api stack on a namespaced resource ?

@AlexEscalante
Copy link

I am having the same problem with a setup very much like the one @brianlittmann has. When including rails-api gem, devise starts to complain because of the lack of flash middleware on the stack.

There doesn't seem to be a way to have two middleware stacks, each for the right controller. Seems to be a rack limitation but the documentation should be completely straightforward about this to avoid people losing time. Seems like I will avoid rails-api gem for a better solution, maybe using ActionController::Metal.

@alexdesi
Copy link

Hi all, any news about this issue?
at the end how did you guys tackled the problem "Rails API + Admin area" without loading Rails default middleware stack for the API?

@brianlittmann
Copy link
Author

@alexdesi I compromised and just had a root API module controller that inherited from ActionController::Metal. In there, I used ActionController::Base.without_modules to specify unneeded modules. Honestly though, unless performance is a known issue, life will be a bit easier by just using the default Rails stack.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants