Yii2-rest-api-basic-application-template-

Basic Rest API Using Basic Template of Yii2

Welcome to GitHub Pages.

This automatic page generator is the easiest way to create beautiful pages for all of your projects. Author your page content here using GitHub Flavored Markdown, select a template crafted by a designer, and publish. After your page is generated, you can check out the new branch:

$ cd your_repo_root/repo_name
$ git fetch origin
$ git checkout gh-pages

If you're using the GitHub for Mac, simply sync your repository and you'll see the new branch.

Here you can see the configuration, i have done.

Basic Rest API Using Basic Template of Yii2. Here, i have configured rest api for basic application template in Yii2, hope this will helps.

There are several approaches to do the web-service, but i prefer the way of configuring rest with in app modules as following ways.


-@app -modules -api -modules -v1 // Prefer way of configuring web services {http://www.example.com/api/v1/someController/someAction} -v2 // For future version. v2.0

*Note the api module have nested modules which can be configured by any ways. Either in config.php or as in the following *

<?php

namespace app\modules\api;

/** * A Parent API Module. * This might contains nested modules, as defined in init(); * * @author TNChalise <teknarayanchalise@outlook.com> * @created_on : 18 Dec, 2014, 9:41:45 PM * @package pp\modules\api\Api * @version 1.0 */ class Api extends \yii\base\Module {

`public function init()`
`{`
    `parent::init();`

    `$this->modules = [`
        `'v1' => [`
            `// you should consider using a shorter namespace here!`
            `'class' => 'app\modules\api\modules\v1\VersionOne',`
        `],`
        `'v2' => [`
            `// you should consider using a shorter namespace here!`
            `'class' => 'app\modules\api\modules\v2\VersionTwo',`
        `],`
    `];`
`}`

}

And with the some url-manager magic, you are done with the rest-confuguration. Please see the UserController under app\modules\api\modules\v1\controllers, for the verbs allowed.

See the following files for configurations: