Closed polinwei closed 6 years ago
Hello!
You can use the analogy of User api.
'api\modules\v1\controllerlers\BlogController.php'.
http://www.yiiframework.com/doc-2.0/guide-rest-quick-start.html
You can do in by analogy the backend, as an example: https://github.com/Dominus77/yii2-advanced-start/tree/api_module_dev Api is made for the users module References for access:
http://mysite.com/api/users
http://mysite.com/api/user/1
Basic moments:
Now for Users RESTful is available:
http://yii2-advanced-start.loc/api/users // All users
http://yii2-advanced-start.loc/api/user/1 // User with ID=1
Since we have not disabled the old api in the config, it is also available:
http://yii2-advanced-start.loc/api/v1/users // All users
http://yii2-advanced-start.loc/api/v1/users/1 // User with ID=1
By this principle, you can add api to other modules.
Hi Sir: Thanks. It is helpful. I will try it.
Why is the value 'controller' => [ 'users/default']
in BootstrapApi.php ?
I think I have fully understand. I also finished the REST for blog. Thanks for your detail document.
Why is the value 'controller' => [ 'users/default'] in BootstrapApi.php ?
http://www.yiiframework.com/doc-2.0/guide-rest-quick-start.html#configuring-url-rules
Hi Sir:
If I want to add a RESTful-API for blog , Which directory is better to put? like 'api\modules\v1\controllers'. Is there anything to pay attention to?