3

I am using the HTTParty gem to make a patch request to update an object via an API call as follows:

params = { first_name: "John"}

@options = {params: params}
@response = HTTParty.patch("http://localhost:3000/1/kites/4", @options)

But on the API side, within the update method that the above PATCH request is supposed to call I only see the following parameters available:

{"format"=>"json",
 "controller"=>"api/v1/kites",
 "action"=>"update",
 "version"=>"1",
 "id"=>"4"}

An error message is passed back to the @response for pasrsing.

What happened to first_name and/or how do I call HTTParty.patch appropriately if that is indeed what is causing the loss of the parameters passed to the API?

EDIT:

As it turns out, if I do

@options = {query: params}

that will work but only if I keep a query under a certain size....

Nona
  • 5,302
  • 7
  • 41
  • 79

1 Answers1

4

Not sure what your 'patch' action does exactly in your API but the documentation says that you need to pass a URL and params in a body: key, like so:

HTTParty.patch('site/your_url', body: { key1: value, key2: value })

Alternalitvely, you can pass the params in query: key which appends the params to the URI.

HTTParty.patch('site/your_url', query: { key1: value, key2: value })

jedi
  • 2,003
  • 5
  • 28
  • 66