【问题标题】:Devise POST api test设计 POST api 测试
【发布时间】:2014-10-24 14:45:22
【问题描述】:

我正在使用 Devise 构建用户 API 函数。 这是referring tutorial

以下是路线:

api_customers_path  POST    /customers(.:format)    api/v1/customers#create {:format=>:json, :subdomain=>"api"}
api_customer_path   GET /customers/:id(.:format)    api/v1/customers#show {:format=>:json, :subdomain=>"api"}
PATCH   /customers/:id(.:format)    api/v1/customers#update {:format=>:json, :subdomain=>"api"}
PUT /customers/:id(.:format)    api/v1/customers#update {:format=>:json, :subdomain=>"api"}
DELETE  /customers/:id(.:format)    api/v1/customers#destroy {:format=>:json, :subdomain=>"api"}
api_sessions_path   POST    /sessions(.:format) api/v1/sessions#create {:format=>:json, :subdomain=>"api"}
api_session_path    DELETE  /sessions/:id(.:format) api/v1/sessions#destroy {:format=>:json, :subdomain=>"api"}

我想知道如何测试 Create api (POST)。 我尝试使用 Postman 进行测试,但结果出乎意料。

我的测试有什么问题? 如果我测试 GET api,它可以正常工作。

【问题讨论】:

    标签: ruby-on-rails ruby rspec devise


    【解决方案1】:

    您为 API 提供的参数名称对于设计生成的用户来说是错误的。它们应该是:

    user[email]
    user[password]
    user[password_confirmation]
    

    您可能还需要authenticity_token 才能使其正常工作。您可以通过在视图中键入来生成一个来测试您的 API。

    <%= form_authenticity_token %>
    

    祝你好运!

    【讨论】:

      猜你喜欢
      • 2019-07-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-09-16
      • 1970-01-01
      • 2017-11-02
      • 2011-09-17
      • 2016-08-04
      相关资源
      最近更新 更多