Skip to content

Commit 789c89e

Browse files
Merge pull request chriskacerguis#363 from admin36/master
Add Controller Method Limits Documentation and Example
2 parents 438e254 + 26fb607 commit 789c89e

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

application/config/rest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,12 @@
420420
PRIMARY KEY (`id`)
421421
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
422422
|
423+
| To specify limits, within your Controller __construct() method add per-method
424+
| limits with:
425+
426+
$this->method['METHOD_NAME']['limit'] = [NUM_REQUESTS_PER_HOUR];
427+
428+
| See application/controllers/api/example.php for examples.
423429
*/
424430
$config['rest_enable_limits'] = FALSE;
425431

application/controllers/api/example.php

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,20 @@
1818

1919
class Example extends REST_Controller
2020
{
21-
function user_get()
21+
function __construct()
22+
{
23+
// Construct our parent class
24+
parent::__construct();
25+
26+
// Configure limits on our controller methods. Ensure
27+
// you have created the 'limits' table and enabled 'limits'
28+
// within application/config/rest.php
29+
$this->methods['user_get']['limit'] = 500; //500 requests per hour per user/key
30+
$this->methods['user_post']['limit'] = 100; //100 requests per hour per user/key
31+
$this->methods['user_delete']['limit'] = 50; //50 requests per hour per user/key
32+
}
33+
34+
function user_get()
2235
{
2336
if(!$this->get('id'))
2437
{

0 commit comments

Comments
 (0)