A fully featured Advanced Improved Template with RESTful Api support.
Yii2-advanced-improved-template-restful-api is based on yii2-advanced-template created by nenad-zivkovic. The base template is upgraded with inbuilt REST Api support.
- Clone the repository
git clone https://github.com/choxx/yii2-advanced-improved-template-restful-api.git
. - Now open terminal and navigate to yii2-advanced-improved-template-restful-api/_protected.
- Now type the command
php init
and press 0 for development mode. - Press yes to continue initializing the template.
- Now navigate to root directory of app via hitting
cd ..
. - Run command
sudo composer update
to build/update the dependencies. - After completion, configure you database in common/config/main-local.php.
- Now navigate to _protected
cd _protected
. - Apply migrations by hitting
yii migrate
. - Apply RBAC migration by hitting
yii rbac/init
. - Now create table country with sample data
CREATE TABLE `country` (
`code` CHAR(2) NOT NULL PRIMARY KEY,
`name` CHAR(52) NOT NULL,
`population` INT(11) NOT NULL DEFAULT '0'
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
INSERT INTO `Country` VALUES ('AU','Australia',18886000);
INSERT INTO `Country` VALUES ('BR','Brazil',170115000);
INSERT INTO `Country` VALUES ('CA','Canada',1147000);
INSERT INTO `Country` VALUES ('CN','China',1277558000);
INSERT INTO `Country` VALUES ('DE','Germany',82164700);
INSERT INTO `Country` VALUES ('FR','France',59225700);
INSERT INTO `Country` VALUES ('GB','United Kingdom',59623400);
INSERT INTO `Country` VALUES ('IN','India',1013662000);
INSERT INTO `Country` VALUES ('RU','Russia',146934000);
INSERT INTO `Country` VALUES ('US','United States',278357000);
Navigate to the root directory of application yii2-advanced-improved-template-restful-api/_protected and create a localserver by hitting
php -S localhost:7872
and you are ready with your template.
- Check for frontend http://localhost:7872.
- Check for backend http://localhost:7872/backend.
- Check for REST api
http://localhost:7872/api/v1/countries
Parameters
code - SU
name - Sudan
population - 7872
http://localhost:7872/api/v1/countries/SU
Parameters
population - 10000