如何记录Koala API请求和回复?
我在通过 API 调用与 Facebook 交互的应用程序中使用 Koala。我想在数据库中记录 Koala 生成的原始 HTTP 请求以及 Facebook 发回的响应。我怎样才能抓住这些字符串以便保存它们?
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 Facebook sends back in a database. How can I grab these strings so that I can save them?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是一个老问题,但我自己找不到如何调试 Koala 请求的直接示例。
Koala 使用 Faraday,它具有极强的可扩展性。它基于 Rack 中间件,Koala 为此设置了默认中间件。以下是如何将
STDOUT
日志记录添加到 Faraday 中间件:有关 HTTP 请求的 Koala 文档:
https://github.com/arsduo/koala/wiki/HTTP-Services
您可以在此处阅读有关如何使用 Faraday 以及我从何处获取记录器的更多信息:
https://mislav.net/2011/07/faraday-advanced-http/
希望这可以帮助其他正在寻找一种简单方法来调试对 Facebook Graph API 的 Koala HTTP 请求的人!
This is an old question, but I couldn't find a straight-forward example of how to debug Koala requests myself.
Koala uses Faraday, which is extremely extensible. It's based on Rack middleware, for which Koala sets up default middleware. Here's how to add logging to
STDOUT
to the Faraday middleware:Koala documentation about HTTP requests:
https://github.com/arsduo/koala/wiki/HTTP-Services
You can read more about how to use Faraday and where I got the logger from right here:
https://mislav.net/2011/07/faraday-advanced-http/
Hopefully this helps anyone else looking for a simple way to debug Koala HTTP requests to the Facebook Graph API!