Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1035973
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T14:37:39+00:00 2026-05-16T14:37:39+00:00

I can’t seem to find much information on the web about the different approaches

  • 0

I can’t seem to find much information on the web about the different approaches to building a REST API in Rails; so I kinda have two questions:

  1. Can someone point me to some articles that show the pros/cons of the different
    approaches?
  2. Would you please share your thoughts on the pros/cons of the following approaches?

 

Proposed Approaches

 

  1. Use the standard controllers to return XML when a users adds .xml to the end
    of the URL

    Pros:

    • This is built-in to Rails and very easy to use
    • Follows the same resource-based approach that Rails has, so it will be easy for
      existing users to understand/remember

    Cons:

    • API isn’t cleanly separated from the main site, harder to maintain
    • People may assume that adding .xml will work in places it doesn’t

  2. Use namespaced routing to create separate API controllers that only handle API
    functions, but still have access to the same models that the website uses

    Pros:

    • API is mostly separated
    • Still uses resource-full controllers

    Cons:

    • URLs have the form of site.com/api/resource.xml which may make people assume all
      resources are available
    • API is still part of the website code/project; thus, harder to maintain

  3. Use route forwarding and constraints to forward all API calls to a Rack
    application

    Pros:

    • API is fully separated
    • Not required to use Resource-full style if we don’t want to
    • URLs clearly show it’s an API and you should check the docs to see what’s available
      (at least, my mind works this way; I assume other dev’s minds do too)

    Cons:

    • Harder to use models from website code
    • Easier to maintain as a separate project, but that means harder to integrate with
      existing site
    • Must keep codebases in sync since models may change for site features/bug fixes

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T14:37:40+00:00Added an answer on May 16, 2026 at 2:37 pm

    I would propose that the API being in the same project as your website isn’t a bad thing as long as the code is DRY*. Like you pointed out, having separate codebases is a challenge because you have to keep them in sync with every feature/bugfix you do. It’s easier to maintain if they are in the same place. As long as you keep your code DRY, this method is the clear winner.

    I would offer XML and JSON from the controllers with a subdomain handled by Rails’s routing engine. When someone has picked up on the pattern of api.site.com/resource.xml and tries to access a resource that isn’t there, it’s really not a big deal. As long as your API is documented clearly and you fail/error gracefully when they try to access a resource not in your API, it should be just fine. I would try to return a message saying that resource isn’t available and a url to your api documentation. This shouldn’t be a runtime problem for any API consumers, as this should be part of discovering your API.

    Just my $0.02.

    *DRY = Don’t Repeat Yourself. DRY code means you don’t copy-paste or rewrite the same thing for your site and your api; you extract and call from multiple places.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
We're building an app, our first using Rails 3, and we're having to build
Can anyone help me trying to find out why this doesn't work. The brushes
Can't seem to get the Back Button to appear in a UINavigationController flow. I
Can somebody point me to a resource that explains how to go about having
Can anyone (maybe an XSL-fan?) help me find any advantages with handling presentation of
Can you tell me what is the difference between abstraction and information hiding in
Can we write all the control events in a seperate class file in different
Can anybody give me a hint about how to load product's media gallery along
Can I open my custom developed form [instead of native one] when user opens

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.