简体   繁体   中英

Configure Rails-API for 'normal' rails

The Rails-API gem provides a way to develop REST APIs with Rails. To this end it disables features from 'normal' rails used for developing web applications. When developing a web application that both renders html and serves API requests these features must be turned back on.

Question: What configuration and settings need to be changed to enable all features necessary for normal Rails development? Please keep ApplicationController inheriting from ActionController:API for the API part.

Things to consider:

  • Changes to application.rb :
    • Which middlewares are missing?
  • Which helpers to include in ApplicationController ?
  • Gems?
  • Now serving both JSON and HTML.
  • What impact does config.api_only = false have?

What @Prakash said. I'd only use the Rails-API gem if I was sure the app is only going to serve an API, precisely because of the flurry of questions that crop up if that assumption is violated. By contrast, it's easy to take a "full-size" Rails app and add robust API support.

If you're trying to convert an existing Rails-API app to something that can serve HTML, I'd start by looking at this section of the Rails-API readme and use it as basically a checklist to follow in reverse. I'd also whip up an empty "reference" app in full Rails, so when you're looking at each config file you have a pure-blood app to compare against.

Either way, good luck!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM