Giter Site home page Giter Site logo

Comments (20)

kurenn avatar kurenn commented on July 29, 2024 1

That is why, you have to change that to respond to a path instead of an api as discussed in here #52

from market_place_api.

EchoLiao avatar EchoLiao commented on July 29, 2024

I found the reason. It should POST http://api.myapi2.dev/users. The URI /users/sign_up(.:format) is to request the sign up form page.

screen shot 2015-06-07 at 5 12 18 pm

_But_ there is a new issue. After I submit by click the Send button, it can create new user successfully in database, but Postman still result in errors. Why?

screen shot 2015-06-07 at 5 12 30 pm

screen shot 2015-06-07 at 5 12 44 pm

from market_place_api.

kurenn avatar kurenn commented on July 29, 2024

You should post to the users controller create action, do you have an example on how it looks like?

from market_place_api.

EchoLiao avatar EchoLiao commented on July 29, 2024
     api_users POST   /users(.:format)                       api/v1/users#create {:format=>:json, :subdomain=>"api"}
     user_registration POST   /users(.:format)            devise/registrations#create

Yes, but the URI /users has two match. It seem to match with the first one. I don't known why.
What does example mean?

from market_place_api.

kurenn avatar kurenn commented on July 29, 2024

You can remove the devise routes, they are not being used

from market_place_api.

EchoLiao avatar EchoLiao commented on July 29, 2024

I can't remove it directly. Because i add devise email confirmation for register.
It add three routes:

       user_confirmation POST   /users/confirmation(.:format)          devise/confirmations#create
   new_user_confirmation GET    /users/confirmation/new(.:format)      devise/confirmations#new
                         GET    /users/confirmation(.:format)          devise/confirmations#show

The first one is need. Is there a way to remove the useless devise routes only?

from market_place_api.

kurenn avatar kurenn commented on July 29, 2024

remove then the :registrable module from the user model that should work!

from market_place_api.

EchoLiao avatar EchoLiao commented on July 29, 2024

I just try it, it worked! Many thanks!

from market_place_api.

EchoLiao avatar EchoLiao commented on July 29, 2024

I think the forms GET routes should remove too.
Such as:

   new_user_password GET    /users/password/new(.:format)          devise/passwords#new
   edit_user_password GET    /users/password/edit(.:format)         devise/passwords#edit

but retain the POST routes:

                      PATCH  /users/password(.:format)              devise/passwords#update
                      PUT    /users/password(.:format)              devise/passwords#update

How can i do it?

from market_place_api.

kurenn avatar kurenn commented on July 29, 2024

It has to be with the devise modules, maybe the recoverable? or some other....

from market_place_api.

janotterstetter avatar janotterstetter commented on July 29, 2024

Hi,

from reading this I think one should link this issue with the following issue: #8

Seems that they're about the same things regarding devise routes an the apionrails user controller routes.

Any idea how to solve the "duplicate" routes?
From my point of view the don't use devise options like "recoverable" won't solve the issue.

As I understand we choose devise for the authentication stuff and won't get rid of it.
What about not using the apionrails user controller routes?

Best

Jan

from market_place_api.

kurenn avatar kurenn commented on July 29, 2024

Yeah that, could be a good solution, not to use the users_controller but we will have to override the one on devise.

A good solution would be as describe on issue #8 just move the devise_for :users call after the :api namespace...

from market_place_api.

janotterstetter avatar janotterstetter commented on July 29, 2024

@kurenn thanks for your reply :-)

When I move the the devise_for :users call after the :api namespace the routes are listed beneath our :api path. Thats fine, but we do have duplicate routes now.

When I bundle exec rspec spec all tests passes. Thats fine.
But our specs are using our own user / session controllers and not the ones of devise.

Question:
Why we are not using the devise controllers?
Don't we want to use devise for the heavy authentication stuff, register a new user, sign in, sign out etc.?

Devise don't return json responses when used as is. Shouldnt we inherit from the devise controllers?

When I don't use the above "hack" (remove then the :registrable module from the user model) and try to use postman to create a user I'm getting "routing error - uninitialized constant Api::V1::RegistrationsController" due to the routes "mismatch" of our own and of the devise routes.

My rake routes:

Prefix Verb URI Pattern Controller#Action
    new_api_user_session GET    | /users/sign_in(.:format)       | api/v1/sessions#new {:format=>:json, :subdomain=>"api"}
        api_user_session POST   | /users/sign_in(.:format)       | api/v1/sessions#create {:format=>:json, :subdomain=>"api"}
destroy_api_user_session DELETE | /users/sign_out(.:format)      | api/v1/sessions#destroy {:format=>:json, :subdomain=>"api"}
       api_user_password POST   | /users/password(.:format)      | api/v1/passwords#create {:format=>:json, :subdomain=>"api"}
   new_api_user_password GET    | /users/password/new(.:format)  | api/v1/passwords#new {:format=>:json, :subdomain=>"api"}
  edit_api_user_password GET    | /users/password/edit(.:format) | api/v1/passwords#edit {:format=>:json, :subdomain=>"api"}
                         PATCH  | /users/password(.:format)      | api/v1/passwords#update {:format=>:json, :subdomain=>"api"}
                         PUT    | /users/password(.:format)      | api/v1/passwords#update {:format=>:json, :subdomain=>"api"}

cancel_api_user_registration GET | /users/cancel(.:format) | api/v1/registrations#cancel {:format=>:json, :subdomain=>"api"}
api_user_registration POST | /users(.:format) | api/v1/registrations#create {:format=>:json, :subdomain=>"api"}
new_api_user_registration GET | /users/sign_up(.:format) | api/v1/registrations#new {:format=>:json, :subdomain=>"api"}
edit_api_user_registration GET | /users/edit(.:format) | api/v1/registrations#edit {:format=>:json, :subdomain=>"api"}
PATCH | /users(.:format) | api/v1/registrations#update {:format=>:json, :subdomain=>"api"}
PUT | /users(.:format) | api/v1/registrations#update {:format=>:json, :subdomain=>"api"}
DELETE | /users(.:format) | api/v1/registrations#destroy {:format=>:json, :subdomain=>"api"}
api_users POST | /users(.:format) | api/v1/users#create {:format=>:json, :subdomain=>"api"}
api_user GET | /users/:id(.:format) | api/v1/users#show {:format=>:json, :subdomain=>"api"}
PATCH | /users/:id(.:format) | api/v1/users#update {:format=>:json, :subdomain=>"api"}
PUT | /users/:id(.:format) | api/v1/users#update {:format=>:json, :subdomain=>"api"}
DELETE | /users/:id(.:format) | api/v1/users#destroy {:format=>:json, :subdomain=>"api"}
api_sessions POST | /sessions(.:format) | api/v1/sessions#create {:format=>:json, :subdomain=>"api"}
api_session DELETE | /sessions/:id(.:format) | api/v1/sessions#destroy {:format=>:json, :subdomain=>"api"}

Question
I guess the crucial part to use of devise is the registration / password recover process etc.
So how can we use the crucial parts of devise and then use our "own" controllers for the "simple" stuff as showing, updating the user?

In future version one can image to use devise omniauth feature to register users with out api app that are google+ or twitter or etc. user.

Best

Jan

from market_place_api.

oeddyo avatar oeddyo commented on July 29, 2024

@kurenn Also curious to @janotterstetter 's question. Could you help us out please?

from market_place_api.

kurenn avatar kurenn commented on July 29, 2024

@janotterstetter Yeah you could use devise to register users, but you will have to override the registrations controller from devise to meet your needs, and on the tutorial I wanted to keep it super simple to register users.

Now to get the users controller create action to work, using postman:

screen shot 2015-07-31 at 12 17 16 pm

Please let me know how it goes, sorry for the delay on the answer!

from market_place_api.

lesreaper avatar lesreaper commented on July 29, 2024

I'm not sure how to test. I'm using localhost:3000, and none of my postman stuff works. Does this have to be loaded on a server to test the API?

from market_place_api.

kurenn avatar kurenn commented on July 29, 2024

Do you have the subdomain setup on your routes file?

from market_place_api.

lesreaper avatar lesreaper commented on July 29, 2024

Yes.

from market_place_api.

lesreaper avatar lesreaper commented on July 29, 2024

Thanks for getting back to me last time. I appreciate it. I took a crack at your ticket suggestion and implemented it in my routes as seen below.

Now, I’m getting all kinds of timeouts and routing errors. I’m hoping that things are working as I go through, but I’m almost done with the book and have no idea if anything I’m doing is working on the API end, though the tests work great. I attached my log.

What am I doing wrong here?

Here is my routes

require 'api_constraints'

HapnApp::Application.routes.draw do

mount SabisuRails::Engine => "/sabisu_rails"

devise_for :users

namespace :api, path: '/api' do
scope module: :v1,
constraints: ApiConstraints.new(version: 1, default: true) do

  resources :users, :only => [:show, :create, :update, :destroy]
  resources :sessions, :only => [:create, :destroy]
  resources :events, :only => [:show, :index]


end

end
end

All I really need to know at the end of this is:

  1. What is the URL I’m going to access to get my resource information, both as I develop on my local machine and then again on Heroku?
  2. How do I test this URL as I’m creating my site?

I know this can’t be difficult once you learn it, but man, it seems a long way off.

Thanks,

Rich

On Nov 26, 2015, at 7:01 PM, Abraham <[email protected]mailto:[email protected]> wrote:

That is why, you have to change that to respond to a path instead of an api as discussed in here #52#52


Reply to this email directly or view it on GitHubhttps://github.com//issues/33#issuecomment-160007925.

from market_place_api.

kurenn avatar kurenn commented on July 29, 2024

@lesreaper Now you will have to access the resources like:

api/v1/users/ or whatever you want to access

from market_place_api.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.