Build REST API With Yii2
yii provides a whole set of tools to simplify the task of implementing RESTful Web Service APIs. Here I am goint build an example REST APIs with yii2. Lets get started.
- open phpstorm, create an empty project, and initial composer.
- Open cmd, locate to project folder
Run following two composer commends:
composer global require “fxp/composer-asset-plugin:^1.2.0”
composer create-project –prefer-dist yiisoft/yii2-app-basic basicIf you need learn more about composer, checkout: https://getcomposer.org/
Now upload whole project to the server
Change the ownership of the website folder
cd /home/wwwroot/project1.abc.com
chown www:www ./ -ROpen the browser
Database connection
Configure the url manager
Now we can generate model class by Gii. Open the url:
http://project1.abc.com/basic/web/index.php?r=giiWe have customer table, just use this table
Use this model as the model of our controller
Make a request