kurenn / market_place_api

The API on Rails tutorial application
142 stars 70 forks source link

3.2.1 Routing error #64

Open ninjabunny-dev opened 8 years ago

ninjabunny-dev commented 8 years ago

I"m getting a ActionController::RoutingError (No route matches [GET] "/users/1.json")

I have tried curl -H 'Accept: application/api.bluemage.systems.v1' 'http://10.0.0.11:3000/users/1.json'

curl -H 'Accept: application/api.bluemage.systems.v1' 'http://10.0.0.11:3000/users/1'

curl -H 'Accept: application/api.bluemage.systems.v1' http://10.0.0.11:3000/users/1

and none of them work, the route shows up with rake routes.

ghost commented 8 years ago

Mind showing us what your routes file looks like, as well as the output from rake routes?

kurenn commented 8 years ago

Is the devise_for :users line before the api namespace?

OxenBoxen commented 8 years ago

It's not working for me either, here is my command: "curl -H 'Accept: application/application/vnd.marketplace.v1' http://api.market_place_api.dev/users/1" . I have devise_for :users before the api namespace

Here is my routes.rb:

MarketPlaceApi::Application.routes.draw do

devise_for :users

namespace :api, defaults: { format: :json}, constraints: { subdomain: 'api' }, path: '/' do

scope module: :v1, constraints: ApiConstraints.new(version: 1, default: true) do 

    # list resources
    resources :users, :only => [:show]

end

end

end

ghost commented 8 years ago

Any errors being produced? Do you see the connection being attempted from your rails console?

kurenn commented 7 years ago

@OxenBoxen is there any update on this? were you able to solved it?

fabOnReact commented 6 years ago

I have the same problem too..

curl: (7) Failed to connect to api.market_place_api.dev port 80: Connection refused

this is my route file

MarketPlaceApi::Application.routes.draw do
  # Api definition
  namespace :api, defaults: { format: :json }, constraints: { subdomain: 'api' }, path: '/'  do
    scope module: :v1, constraints: ApiConstraints.new(version: 1, default: true) do
      resources :users, :only => [:show]
    end
  end

  devise_for :users
end

this is my curl command curl -H 'Accept: application/application/vnd.marketplace.v1' http://api.market_place_api.dev/users/1

also, my main question.. can we do this without actually starting a server at http://api.market_place_api.dev?

thanks

fabOnReact commented 6 years ago

I was able to make this work based on the following answer from Phanindra

To use localhost:3000/api/v1/users/1 change routes.rb to this

namespace :api, defaults: { format: :json } do
namespace :v1 do
devise_for :users
resources :users, :only => [:show]
end
end

later I try to use the namespaces as in the guide, but right now it is not my priority

I do the following curl command and I receive the json response,

curl 'http://0.0.0.0:3000/api/v1/users/1'
{"id":1,"email":"example@marketplace.com","created_at":"2017-10-26T13:54:18.343Z","updated_at":"2017-10-26T13:54:18.343Z"}

I have a server running on localhost:3000