我使用以下代码在CodeIgniter中构建了一个REST API:https://github.com/chriskacerguis/codeigniter-restserver
并尝试为此处提到的每种方法设置限制:
CodeIgniter RESTful API rate limiting issue
但它不起作用。
我在rest.php文件中启用了限制,但它仍然没有计算限制。
我的代码:
/*
|--------------------------------------------------------------------------
| REST Enable Limits
|--------------------------------------------------------------------------
|
| When set to TRUE, the REST API will count the number of uses of each method
| by an API key each hour. This is a general rule that can be overridden in the
| $this->method array in each controller
|
| Default table schema:
| CREATE TABLE `limits` (
| `id` INT(11) NOT NULL AUTO_INCREMENT,
| `uri` VARCHAR(255) NOT NULL,
| `count` INT(10) NOT NULL,
| `hour_started` INT(11) NOT NULL,
| `api_key` VARCHAR(40) NOT NULL,
| PRIMARY KEY (`id`)
| ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
| To specify the limits within the controller's __construct() method, add per-method
| limits with:
|
| $this->method['METHOD_NAME']['limit'] = [NUM_REQUESTS_PER_HOUR];
|
| See application/controllers/api/example.php for examples
*/
$config['rest_enable_limits'] = TRUE;
/*
|--------------------------------------------------------------------------
| REST API Limits Table Name
|--------------------------------------------------------------------------
|
| If not using the default table schema in 'rest_enable_limits', specify the
| table name to match e.g. my_limits
|
*/
$config['rest_limits_table'] = 'rest_api_limits';
这是我的Controller中的方法数组:
protected $methods = array(
'properties_get' => array('level' => 20),
'images_get' => array('level' => 20),
'prices_get' => array('level' => 20),
'availability_get' => array('level' => 20),
'portals_get' => array('level' => 20, 'limit' => 10),
'properties_post' => array('level' => 20, 'limit' => 10),
'images_post' => array('level' => 20, 'limit' => 10),
'availability_post' => array('level' => 20, 'limit' => 10),
'prices_post' => array('level' => 20, 'limit' => 10),
'enquiries_post' => array('level' => 20, 'limit' => 100),
'properties_put' => array('level' => 20, 'limit' => 10),
'enquiries_get' => array('level' => 20, 'limit' => 10),
'bookings_get' => array('level' => 20, 'limit' => 10),
'ferienhausmiete_get' => array('level' => 10, 'limit' => 20),
'homeaway_get' => array('level' => 10, 'limit' => 600),
);
有什么建议吗?在此先感谢!!!