PHPackages                             dersonsena/yii2-app-restapi - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Framework](/categories/framework)
4. /
5. dersonsena/yii2-app-restapi

ActiveProject[Framework](/categories/framework)

dersonsena/yii2-app-restapi
===========================

Yii 2 Rest API Project Template

2.0.14(8y ago)31172BSD-3-ClausePHPPHP &gt;=5.4.0

Since Dec 1Pushed 8y ago1 watchersCompare

[ Source](https://github.com/dersonsena/yii2-app-restapi)[ Packagist](https://packagist.org/packages/dersonsena/yii2-app-restapi)[ Docs](http://www.yiiframework.com/)[ RSS](/packages/dersonsena-yii2-app-restapi/feed)WikiDiscussions master Synced 2mo ago

READMEChangelog (3)Dependencies (9)Versions (21)Used By (0)

 [ ![](https://avatars0.githubusercontent.com/u/993323) ](https://github.com/yiisoft)

Yii 2 API Rest Project Template
===============================

[](#yii-2-api-rest-project-template)

Yii 2 API Rest Project Template is a skeleton [Yii 2](http://www.yiiframework.com/) application best for rapidly creating API Rest projects.

DIRECTORY STRUCTURE
-------------------

[](#directory-structure)

The directory structure is similar to the Basic template added in the Advanced feature, which is the generation of the `*-local.php`, `web/index.php` files, and the `yii` script according to your environment

```
  + assets/             contains assets definition
  + components/         containes the application components
  + commands/           contains console commands (controllers)
  - config/             contains application configurations
    * routes/           contains the routes configurations files
  + environments        contains environments templates files (see the advanced template)
  + mail/               contains view files for e-mails
  + migrations/         contains the migrations scripts
  + models/             contains model classes
  + modules/            contains de application modules
  + runtime/            contains files generated during runtime
  + tests/              contains various tests for the basic application
  + vendor/             contains dependent 3rd-party packages
  + web/                contains the entry script and Web resources

```

REQUIREMENTS
------------

[](#requirements)

The minimum requirement by this project template that your Web server supports PHP 5.4.0.

INSTALLATION
------------

[](#installation)

### Install via Composer

[](#install-via-composer)

If you do not have [Composer](http://getcomposer.org/), you may install it by following the instructions at [getcomposer.org](http://getcomposer.org/doc/00-intro.md#installation-nix).

You can then install this project template using the following command:

```
php composer create-project --stability=dev dersonsena/yii2-app-restapi

```

Now you should be able to access the application through the following URL, assuming `basic` is the directory directly under the Web root.

```
http://localhost/basic/web/

```

### Install with Docker

[](#install-with-docker)

Update your vendor packages

```
docker-compose run --rm php composer update --prefer-dist

```

Run the installation triggers (creating cookie validation code)

```
docker-compose run --rm php composer install

```

Start the container

```
docker-compose up -d

```

You can then access the application through the following URL:

```
http://127.0.0.1:8000

```

See more details in: [https://hub.docker.com/\_/mysql](https://hub.docker.com/_/mysql)

**NOTES:**

- Minimum required Docker engine version `17.04` for development (see [Performance tuning for volume mounts](https://docs.docker.com/docker-for-mac/osxfs-caching/))
- The default configuration uses a host-volume in your home directory `.docker-composer` for composer caches

CONFIGURATION
-------------

[](#configuration)

### Environment Files

[](#environment-files)

Just like in the Advanced template, to generate the files according to your work environment you need to execute the `init` script and then choose your environment: `Development` or `Production`

This script will create the files:

```
  /yii
  /web/index.php
  /config/console-local.php
  /config/web-local.php

```

**NOTES:**

See more details for use in the [Advanced template documentation](https://github.com/yiisoft/yii2-app-advanced/blob/master/docs/guide/start-installation.md).

### Database

[](#database)

Edit the file `config/web-local.php` with real data, for example:

```
'components' => [
    'db' => [
        'class' => 'yii\db\Connection',
        'dsn' => 'mysql:host=127.0.0.1;dbname=your_database_name',
        'username' => 'root',
        'password' => '',
        'charset' => 'utf8',

        // Schema cache options (for production environment)
        //'enableSchemaCache' => true,
        //'schemaCacheDuration' => 60,
        //'schemaCache' => 'cache',
    ],
],
```

**NOTES:**

- Yii won't create the database for you, this has to be done manually before you can access it.
- You also need to configure the database guidelines in `config/console-local.php` for CLI scripts.

### Migration

[](#migration)

Run the migration script to create the users table with the following command:

```
php ./yii migrate

```

The `User.php` model has already been generated by the GII, but a few things have been added. To access it, simply open the `models/User.php` file

**NOTES:**

All models **MUST** extend the `app\components\ModelBase` class. See it for more implementation details.

### API Routes

[](#api-routes)

All your API routes must be within `config/routes`. The following code is the already configured route of users:

```
return [
    [
        'class' => 'yii\rest\UrlRule',
        'controller' => 'v1/system/users',
        'tokens' => ['{id}' => ''],
        'pluralize' => false,
    ]
];
```

### Accessing Users Web Service

[](#accessing-users-web-service)

To access the list of users through your REST API, simply access the address below in your browser or in external applications such as [Postman](https://www.getpostman.com/):

```
GET http:///v1/system/users

```

When accessing this address you should see a list with only one user similar to JSON below:

```
[
    {
        "id": 1,
        "username": "admin",
        "password_reset_token": null,
        "email": "admin@admin.com.br",
        "status": 1,
        "created_at": "09/04/2018 04:18:52",
        "updated_at": "09/04/2018 04:18:52"
    }
]
```

See more details in [RESTful Web Services Guide](https://www.yiiframework.com/doc/guide/2.0/en/rest-quick-start#trying-it-out).

### Authentication

[](#authentication)

The authentication used is [HttpBearerAuth](https://www.yiiframework.com/doc/api/2.0/yii-filters-auth-httpbearerauth), where a Token with [JWT](https://jwt.io/) is passed for user authentication in its API. Initially it is inactive. To activate it is quite simple, just go in the `app\components\BaseController` class and uncomment the lines:

```
$behaviors['authenticator'] = [
    'class' => HttpBearerAuth::className(),
        'except' => $excepts
    ];

    $behaviors['jsxValidator'] = [
        'class' => JsxValidator::className(),
        'except' => $excepts
    ];
]
```

When uncommenting these lines and trying to rerun the list of users, you should return a message as below:

```
{
    "name": "Unauthorized",
    "message": "Your request was made with invalid credentials.",
    "code": 0,
    "status": 401,
    "type": "yii\\web\\UnauthorizedHttpException"
}
```

**NOTES:** If you want some action to be open, that is, do not authenticate to the API, just add inside the `$excepts` array.

For more details on REST authentication with Yii, see the [Official Framework Documentation](https://www.yiiframework.com/doc/guide/2.0/en/rest-authentication).

###  Health Score

33

—

LowBetter than 75% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity15

Limited adoption so far

Community22

Small or concentrated contributor base

Maturity67

Established project with proven stability

 Bus Factor2

2 contributors hold 50%+ of commits

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~84 days

Recently: every ~44 days

Total

20

Last Release

2934d ago

PHP version history (2 changes)2.0.0-alphaPHP &gt;=5.4.0

1.0.0PHP &gt;=7

### Community

Maintainers

![](https://www.gravatar.com/avatar/e48f90b667d26bf572b4858584f2aebb137fc837eccc6cf3001d597d3e808d07?d=identicon)[dersonsena](/maintainers/dersonsena)

---

Top Contributors

[![qiangxue](https://avatars.githubusercontent.com/u/993322?v=4)](https://github.com/qiangxue "qiangxue (147 commits)")[![samdark](https://avatars.githubusercontent.com/u/47294?v=4)](https://github.com/samdark "samdark (113 commits)")[![cebe](https://avatars.githubusercontent.com/u/189796?v=4)](https://github.com/cebe "cebe (78 commits)")[![Ragazzo](https://avatars.githubusercontent.com/u/1748844?v=4)](https://github.com/Ragazzo "Ragazzo (36 commits)")[![SilverFire](https://avatars.githubusercontent.com/u/4499203?v=4)](https://github.com/SilverFire "SilverFire (19 commits)")[![maximal](https://avatars.githubusercontent.com/u/980679?v=4)](https://github.com/maximal "maximal (14 commits)")[![DavertMik](https://avatars.githubusercontent.com/u/220264?v=4)](https://github.com/DavertMik "DavertMik (13 commits)")[![dersonsena](https://avatars.githubusercontent.com/u/9482515?v=4)](https://github.com/dersonsena "dersonsena (13 commits)")[![schmunk42](https://avatars.githubusercontent.com/u/649031?v=4)](https://github.com/schmunk42 "schmunk42 (9 commits)")[![creocoder](https://avatars.githubusercontent.com/u/896494?v=4)](https://github.com/creocoder "creocoder (7 commits)")[![lucianobaraglia](https://avatars.githubusercontent.com/u/374554?v=4)](https://github.com/lucianobaraglia "lucianobaraglia (6 commits)")[![damasco](https://avatars.githubusercontent.com/u/1377554?v=4)](https://github.com/damasco "damasco (5 commits)")[![githubjeka](https://avatars.githubusercontent.com/u/874234?v=4)](https://github.com/githubjeka "githubjeka (5 commits)")[![slavcodev](https://avatars.githubusercontent.com/u/757721?v=4)](https://github.com/slavcodev "slavcodev (4 commits)")[![pana1990](https://avatars.githubusercontent.com/u/6630197?v=4)](https://github.com/pana1990 "pana1990 (4 commits)")[![mohorev](https://avatars.githubusercontent.com/u/4974062?v=4)](https://github.com/mohorev "mohorev (3 commits)")[![ricpelo](https://avatars.githubusercontent.com/u/616169?v=4)](https://github.com/ricpelo "ricpelo (3 commits)")[![Naktibalda](https://avatars.githubusercontent.com/u/395992?v=4)](https://github.com/Naktibalda "Naktibalda (2 commits)")[![numbata](https://avatars.githubusercontent.com/u/82400?v=4)](https://github.com/numbata "numbata (2 commits)")[![Kolyunya](https://avatars.githubusercontent.com/u/2682768?v=4)](https://github.com/Kolyunya "Kolyunya (2 commits)")

---

Tags

frameworkyii2project templatebasic

### Embed Badge

![Health badge](/badges/dersonsena-yii2-app-restapi/health.svg)

```
[![Health](https://phpackages.com/badges/dersonsena-yii2-app-restapi/health.svg)](https://phpackages.com/packages/dersonsena-yii2-app-restapi)
```

###  Alternatives

[developeruz/yii-vue-app

Yii 2 + Vue.js Basic Project Template

1221.6k](/packages/developeruz-yii-vue-app)[yii2mod/base

Base application template for Yii2

531.3k](/packages/yii2mod-base)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
