How to test devise API through Postman?

Viewed 945

I am new to Rails and have setup devise with a User model with email and password with also a React frontend. My aim is to consume the signup/signin endpoints in a React app instead of using the default Rails view. When I go to http://localhost:3000/users/sign_up I can create an account and also see the data in PGadmin. However, I want to create a React based view for the forms and use the endpoint of the devise. I am trying to test the signup api using Postman but gives me an error 422 Unprocessable entity. Not sure what params to pass in Rails.

http://localhost:3000/users/sign_up

Used:

{
    "user": {
        "email": "test2@test.com",
        "password": "test"
    }
}

and

{   
        "email": "test2@test.com",
        "password": "test"
}
1 Answers

First, you are in developement mode, so turn off the token authenticity (and turn on again if on product mode) for Postman requests, by add to app/controllers/application_controller.rb:

class ApplicationController < ActionController::Base
  protect_from_forgery with: :null_session
end

Then, config Postman like this:

Key: user[email]. Value: test2@gmail.com

Key: user[password]. Value: secret

Key: user[password_confirmation]. Value: secret

Click on Send button you will bypass register page and get desire results (such as new user registration informations from Postgres if you not set the Confirmation mode in Devise User)!

Go on!

Related