Search code examples
ruby-on-railsjsonrest-clientfaradaytyphoeus

Cannot read big json response from Ruby


I have two projects which I call them Server and Client projects.

In the Server side, I'm using a web service. I send a certain request to this web service, and it returns me a very long JSON response. Then I can do some business logic, and return my response.

When I send a request from a web browser, I can verify that Server side return what I expected, a very big JSON object (4000 lines long approximately).

The problem starts when I send a request from Client-side to Server-side. I cannot see the full response. All I can see is the top 10 lines, and the bottom 3 lines. The middle part is gone!

I have tried three Ruby gems, which are Rest-client, Typhoeus and Faraday. You can see how I used them below.

P.S. I do not have problems with short responses. But when it comes to big/large/long responses it simply cuts the middle.

Typhoeus:

request = Typhoeus::Request.new( "http://localhost:3000/api/json", method: :get, followlocation: true,
      params: { function: "getAirAvailability", tripType: params[:tripType], departureDateTime: params[:departureDateTime] , destinationLocation: params[:destinationLocation] , originLocation: params[:originLocation] , passenger_adult: params[:adult], passenger_child: params[:child], passenger_infant: params[:infant], passenger_soldier: params[:soldier] },
      headers: { Authorization: "Chg25WxSvQsBsxKyVKyV"})

Faraday:

conn = Faraday.new(:url => 'http://localhost:3000/api/json', headers: { "Authorization" => "Chg25WxSvQsBsxKyVKyV" }) do |faraday|
      faraday.response :logger 
      faraday.adapter  Faraday.default_adapter 
    end
    response = conn.get '/api/json', { function: "getAirAvailability", tripType: "ONE_WAY", departureDateTime: "2016-06-17" , destinationLocation: "ESB" , originLocation: "CKZ" , passenger_adult: 1, passenger_child: 0, passenger_infant: 0, passenger_soldier: 0 }
    return response

Rest-client::

response = RestClient.get "http://localhost:3000/api/json", { params: { function: "getAirAvailability", tripType: "ONE_WAY", departureDateTime: "2016-06-17" , destinationLocation: "ESB" , originLocation: "CKZ" , passenger_adult: 1, passenger_child: 0, passenger_infant: 0, passenger_soldier: 0 } , :Authorization => "Chg25WxSvQsBsxKyVKyV" }

enter image description here


Solution

  • Use method: POST instead of GET

    (because a GET query is restricted with a limit)