yii2 advanced improved template - RESTful Api
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.
Installation
- 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 initand 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 updateto 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 TABLEcountry(codeCHAR(2) NOT NULL PRIMARY KEY,nameCHAR(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);
Running the application
-------------------
>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.
1. Check for frontend **http://localhost:7872**.
2. Check for backend **http://localhost:7872/backend**.
3. Check for REST api
GET
-------------------
1. **http://localhost:7872/api/v1/countries**
2. **http://localhost:7872/api/v1/countries/AU**
POST
-------------------
**http://localhost:7872/api/v1/countries**
>Parameters
code - SU
name - Sudan
population - 7872
PUT
-------------------
**http://localhost:7872/api/v1/countries/SU**
>Parameters
population - 10000
DELETE
-------------------
**http://localhost:7872/api/v1/countries/SU**
[](http://www.yiiframework.com/)
Log in or sign up for Devpost to join the conversation.