我正在使用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"}我想知道的是如何测试创建api (POST)。我尝试使用Postman进行测试,但结果出乎意料。

我的测试出了什么问题?如果我测试GET apis,它可以正常工作。
发布于 2014-12-08 23:43:40
对于devise生成的用户,您为API指定的参数名称是错误的。它们应该是:
user[email]
user[password]
user[password_confirmation]此外,您可能需要一个authenticity_token才能正常工作。您可以通过在视图中键入以下内容来生成一个API来测试您的API。
<%= form_authenticity_token %>祝好运!
https://stackoverflow.com/questions/26550335
复制相似问题