Reputation: 1569
I'm trying to implement an API with rails 4.
When access the API through the browser
http://api.myapp.dev/v1/users/1.json
The JSON response is correct. But when I try to get the JSON using curl
curl http://api.myapp.dev/v1/users/1.json
It returns a html, but basically the error is no route matches [GET] "users/1"
this is my routes file.
Myapp::Application.routes.draw do
devise_for :users
#routes for API
constraints subdomain: 'api' do
scope module: 'api' do
namespace :v1 do
resources :users, :only => [:show]
end
end
end
end
My controller is
class Api::V1::UsersController < ApplicationController
respond_to :json
def show
respond_with User.find(params[:id])
end
end
when I run rake routes
, the route exists:
v1_user GET /v1/users/:id(.:format) api/v1/users#show {:subdomain=>"api"}
Is necessary an extra configuration?
UPDATE I'm using prax as proxy server
Upvotes: 0
Views: 543
Reputation: 107077
I think you need to tell that you accept json
responses:
curl -H "Accept: application/json" http://api.myapp.dev/v1/users/1.json
Upvotes: 2