开发者

REST API for a PHP Web application

开发者 https://www.devze.com 2023-01-24 06:28 出处:网络
I am working on a API 开发者_开发技巧for my web application written in CodeIgniter. This is my first time writing a API.

I am working on a API 开发者_开发技巧for my web application written in CodeIgniter. This is my first time writing a API.

What is the best way of imposing a API limit on the API?

Thanks for your time


Log the user's credentials (if he has to provide them) or his IP address, the request (optional) and a timestamp in a database.

Now, for every request, you delete records where the timestamp is more than an hour ago, check how many requests for that user are still in the table, and if that is more than your limit, deny the request.

Simple solution, keep in mind, though, there might be more performant solutions out there.

Pretty straight forward. If that doesn't answer your question, please provide more details. I don't see how this is codeigniter related, for example.


You can use my REST_Controller to do basically all of this for you:

http://net.tutsplus.com/tutorials/php/working-with-restful-services-in-codeigniter-2/

I recently added in some key logging, request limiting features in so this can all be done through config.


One thing you can do is consider using an external service to impose API limits and provide API management functionality in general.

For example, my company, WebServius ( http://www.webservius.com ) provides a layer that sits in front of your API and can provide per-user throttling (e.g. requests per API key per hour), API-wide throttling (e.g. total requests per hour), adaptive throttling (where throttling limits decrease as API response time increases), etc, with other features coming soon (e.g. IP-address-based throttling). It also provides a page for user registration / issuing API keys, and many other useful features.

Of course, you may also want to look at our competitors, such as Mashery or Apigee.

0

精彩评论

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