-2

I made a post request with RestClient::Request.execute, which works, but sometimes it ended with a 422(Unprocessable Entity).

Afterwards I tried out RestClient.post which didn´t gave me the 422 and worked all the time like a charm.

What is the difference between the two Calls?

I know that with RestClient::Request there are more possibilities for using parameters than with RestClient.post. I do not understand why i get a 422 with one method and not with the other.

Here I used json:

response = RestClient::Request.execute(
        :method => :post,
        :url =>  'http://localhost:3000',
        :timeout => 30,
        :open_timeout => 2,
        :payload => payload.to_json,
        :headers => {
            :content_type => :json,
            :accept => :json
        }
    )

vs.

response = RestClient.post('http://localhost:3000',
          :param1 => 'abc',
          :param2 => "def")
Vasfed
  • 18,013
  • 10
  • 47
  • 53
dan_0
  • 599
  • 1
  • 5
  • 17

1 Answers1

0

They are the same - RestClient.post is a syntax sugar for execute, see restclient's sources, restclient.rb:

def self.post(url, payload, headers={}, &block)
    Request.execute(:method => :post,
       :url => url,
       :payload => payload,
       :headers => headers, &block)
end

The 422 is caused by something else

Vasfed
  • 18,013
  • 10
  • 47
  • 53