market_place_api icon indicating copy to clipboard operation
market_place_api copied to clipboard

3.2.1 Routing error

Open ninjabunny-dev opened this issue 9 years ago • 7 comments

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.

ninjabunny-dev avatar Feb 10 '16 02:02 ninjabunny-dev

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

ghost avatar Feb 10 '16 14:02 ghost

Is the devise_for :users line before the api namespace?

kurenn avatar Feb 12 '16 23:02 kurenn

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

OxenBoxen avatar Jun 07 '16 21:06 OxenBoxen

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

ghost avatar Jun 07 '16 23:06 ghost

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

kurenn avatar Feb 12 '17 19:02 kurenn

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 avatar Oct 26 '17 14:10 fabOnReact

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":"[email protected]","created_at":"2017-10-26T13:54:18.343Z","updated_at":"2017-10-26T13:54:18.343Z"}

I have a server running on localhost:3000

fabOnReact avatar Nov 04 '17 11:11 fabOnReact