Rate limiting
To prevent abuse, you should consider adding rate limiting to your APIs. For example, you may want to limit the API usage of each user to be, at most, five API calls within a period of one minute. If too many requests are received from a user within the stated period of time, a response with the status code 429 (Too Many Requests) should be returned.
Getting ready
Repeat all the steps from the Creating a REST server recipe's Getting ready and How to do it... sections.
Create a migration for creating a user allowance table with the following command:
./yii migrate/create create_user_allowance_table
Then, update the just-created migration method,
up
, with the following code:public function up() { $tableOptions = null; if ($this->db->driverName === 'mysql') { $tableOptions = 'CHARACTER SET utf8 COLLATEutf8_general_ci ENGINE=InnoDB'; } $this->createTable('{{%user_allowance}}', [ 'user_id' => $this->primaryKey...