Ruby send JSON request

后端 未结 10 1312
后悔当初
后悔当初 2020-11-28 20:37

How do I send a JSON request in ruby? I have a JSON object but I dont think I can just do .send. Do I have to have javascript send the form?

Or can I us

10条回答
  •  孤城傲影
    2020-11-28 21:08

    HTTParty makes this a bit easier I think (and works with nested json etc, which didn't seem to work in other examples I've seen.

    require 'httparty'
    HTTParty.post("http://localhost:3000/api/v1/users", body: {user: {email: 'user1@example.com', password: 'secret'}}).body
    

提交回复
热议问题