How can I register Koala API requests and responses?

I use Koala in an application that interacts with Facebook through API calls. I want to record the raw HTTP requests that Koala generates, as well as the responses that Facebook sends back to the database. How can I capture these lines to save them?

+5
source share
1 answer

This is an old question, but I could not find a direct example of how to debug Koala requests.

Koala uses Faraday, which is extremely extensible. It is based on Rack middleware, for which Koala installs default middleware. Here's how to add logging to STDOUTto the Faraday middleware:

# Overwrite the default middleware Proc (evaluated for each request)

Koala.http_service.faraday_middleware = Proc.new do |builder|

  # Add Faraday logger (which outputs to your console)

  builder.use Faraday::Response::Logger

  # Add the default middleware by calling the default Proc that we just replaced
  # SOURCE CODE: https://github.com/arsduo/koala/blob/master/lib/koala/http_service.rb#L20

  Koala::HTTPService::DEFAULT_MIDDLEWARE.call(builder)

end

Koala documentation on HTTP requests:

https://github.com/arsduo/koala/wiki/HTTP-Services

You can learn more about how to use Faraday and where I got the registrar right here:

http://mislav.uniqpath.com/2011/07/faraday-advanced-http/

Hope this helps anyone looking for an easy way to debug Koala HTTP requests to the Facebook API!

+14
source

All Articles