![](/img/trans.png)
[英]How to use postman to request an API that is protected with devise?
[英]How to test devise API through Postman?
我是 Rails 的新手,並且設置了 devise 和用戶 model 和 email 和密碼以及 React 前端。 我的目標是在 React 應用程序中使用注冊/登錄端點,而不是使用默認的 Rails 視圖。 當我從 go 到 http://localhost:3000/users/sign_up 時,我可以創建一個帳戶並在 PGadmin 中查看數據。 但是,我想為 forms 創建一個基於 React 的視圖,並使用 devise 的端點。 我正在嘗試使用 Postman 測試注冊 api 但給我一個錯誤422 Unprocessable entity
。 不確定要在 Rails 中傳遞哪些參數。
http://localhost:3000/users/sign_up
用過的:
{
"user": {
"email": "test2@test.com",
"password": "test"
}
}
和
{
"email": "test2@test.com",
"password": "test"
}
首先,您處於開發模式,因此通過添加到 app/controllers/application_controller.rb 來關閉 Postman 請求的令牌真實性(如果在產品模式下再次打開):
class ApplicationController < ActionController::Base
protect_from_forgery with: :null_session
end
然后,像這樣配置 Postman:
鍵:用戶[電子郵件]。 值:test2@gmail.com
密鑰:用戶[密碼]。 價值:秘密
密鑰:用戶[密碼確認]。 價值:秘密
點擊發送按鈕,您將繞過注冊頁面並獲得所需的結果(例如,如果您未在 Devise 用戶中設置確認模式,則來自 Postgres 的新用戶注冊信息)!
Go 開啟!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.