Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy the api call that works with HTTParty doesn't with Faraday?
    text
    copied!<p>The following is the API call to a remote service that executes successfully when I use with HTTParty.</p> <pre><code>require 'httparty' class TheAPI include HTTParty base_uri 'https://someapp.com' # headers "Content-Type" =&gt; "application/json" def self.create_job post( '/jobs.json', :query =&gt; {:apikey =&gt; "kOrROwbVPNC34VZYhbET", :job =&gt; {:method =&gt; "PUT", :at =&gt; '2012-01-31T18:36:21', :uri =&gt; "http://kasko.com"}}) end end puts TheAPI.create_job </code></pre> <p>But when I try to make the same call using Faraday, I get this unknown error:</p> <pre><code>require 'faraday_stack' conn = Faraday.new 'https://someapp.com', ssl: {verify: false} do |builder| builder.use FaradayStack::ResponseJSON, content_type: 'application/json' builder.use Faraday::Response::Logger#, Logger.new('faraday.log') # builder.use FaradayStack::FollowRedirects, limit: 3 builder.use Faraday::Response::RaiseError # raise exceptions on 40x, 50x responses builder.use Faraday::Adapter::NetHttp end # conn.headers[:user_agent] = 'MyLib v1.2' resp = conn.post "jobs.json", {:apikey =&gt; "kOrROwbVPNC34VZYhbET", :job =&gt; {:method =&gt; "PUT", :at =&gt; '2012-01-31T18:36:21', :uri =&gt; "http://kasko.com"}} puts resp </code></pre> <p>The error raised is:</p> <pre><code>NoMethodError: undefined method ‘bytesize’ for #&lt;Hash:0x000001011ab8f8&gt; method send_request_with_body in http.rb at line 1735 method exec in http.rb at line 1724 method transport_request in http.rb at line 1189 method request in http.rb at line 1177 method block in request in http.rb at line 1170 method start in http.rb at line 627 method request in http.rb at line 1168 method call in net_http.rb at line 51 method call in response.rb at line 8 method call in response.rb at line 8 method call in logger.rb at line 20 method call in response.rb at line 8 method run_request in connection.rb at line 203 method post in connection.rb at line 90 method &lt;main&gt; in test.rb at line 33 </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload