Closed volkanunsal closed 12 years ago
This is possible currently. Look to Request#json
If your Request accepts a body (ie. a POST or PUT), pass a hash into this object and it will be encoded to JSON (using MultiJson). This needs to be better documented and easily exposed in Client
and Resource
interfaces, but for now:
client = MyClient.new
req = client.my_resource
req.json :some => "params"
req.perform # JSON will be sent in the request body
Make sense? Any thoughts on how to make this more clear?
Yeah, it makes perfect sense. I guess it would be helpful to add an example of this into README because this is a important use case for a lot of people.
So how does resource.required and resource.optional work with this?
@jjwilliams It doesn't. Don't use optional
or required
if you're using json in the request body. They are mutually exclusive, since in the case of a POST or PUT request the parameters will be sent in the body as though from a HTML form. If you need to have URL query parameters, attach those in the url without the use of optional
and required
.
I noticed that the current way of sending parameters is a query string. This is a problem for me since my service only accepts JSON objects. Any client library I build would need to support arguments as JSON or convert them into JSON before sending them to the service.