开发者

How do I know who uses my API?

Is there any software I can install that will give me information about my API usage in Rails? I see some API management services but they are all VERY expensive and very complex. I want something to give me basic information about my API.

Also, log analysis seems a way to go. However, I'd like to know if this is the solution that is most used by companies right now. They must use something?

开发者_StackOverflow社区Thanks


if your users already have API key, you can track the activity by following code:

#applications_controller.rb (controller)
after_filter :track_api_usage

private

def track_api_usage
  current_user.api_tracking(params) if params[:api_key]
end


#user.rb (model)
has_many :trackings

def api_tracking(params)
  trackings.create(self.id, params)
end


Why not add an API key which users of your api need to register for, like google maps. Make it as easy as possible otherwise they wont use your api. Having a key for your API means you can prevent usage abuse of your API. I.e. if there is too much traffic from a registered address then you can cut them off.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜