If you want to distinguish between api.mydomain.com and www.mydomain.com and have different controllers for your API requests, then you can certainly use the Rails routes limited to your api subdomain to handle this
constraints :subdomain => "api" do scope :module => "api", :as => "api" do resources :posts end end
which will then use posts_controller.rb in the app / controller / api folder of your application.
Then you have both www.mydomain.com and api.mydomain.com added custom domains for your application, and then the routes will take care of the rest.
You can also look in Grape Gem to help you build api
John beynon
source share