PHPackages                             forecho/yii2-rest-api - 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. forecho/yii2-rest-api

ActiveProject[Framework](/categories/framework)

forecho/yii2-rest-api
=====================

Yii 2 REST API Project Template

v0.0.6(5y ago)4035713[3 PRs](https://github.com/forecho/yii2-rest-api/pulls)BSD-3-ClausePHPPHP &gt;=7.2

Since Jul 18Pushed 3y ago2 watchersCompare

[ Source](https://github.com/forecho/yii2-rest-api)[ Packagist](https://packagist.org/packages/forecho/yii2-rest-api)[ Fund](https://blog-1251237404.cos.ap-guangzhou.myqcloud.com/20190424153431.png)[ Fund](https://blog-1251237404.cos.ap-guangzhou.myqcloud.com/20190424153510.png)[ RSS](/packages/forecho-yii2-rest-api/feed)WikiDiscussions master Synced today

READMEChangelog (6)Dependencies (20)Versions (10)Used By (0)

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

Yii 2 REST API Project Template
===============================

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

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

The template contains the basic features including user join/login api. It includes all commonly used configurations that would allow you to focus on adding new features to your application.

[![Testing](https://github.com/forecho/yii2-rest-api/workflows/Testing/badge.svg)](https://github.com/forecho/yii2-rest-api/actions)[![Lint](https://github.com/forecho/yii2-rest-api/workflows/Lint/badge.svg)](https://github.com/forecho/yii2-rest-api/actions)[![Code Coverage](https://camo.githubusercontent.com/4612a3ed3f81066f4ee0cf5c377de8f3055746caa7adadcd24d43551fa429693/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f666f726563686f2f796969322d726573742d6170692f6261646765732f636f7665726167652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/forecho/yii2-rest-api/?branch=master)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/77af4b771e5e35540110d6b4664490c2c9d7cf8b311755c9d92157717aaa66f3/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f666f726563686f2f796969322d726573742d6170692f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/forecho/yii2-rest-api/?branch=master)[![Latest Stable Version](https://camo.githubusercontent.com/23ba288d86a9c89d945eab7243dc580ee47102447f6d1a5faa069e65c49231ac/68747470733a2f2f706f7365722e707567782e6f72672f666f726563686f2f796969322d726573742d6170692f762f737461626c65)](https://packagist.org/packages/forecho/yii2-rest-api)[![Total Downloads](https://camo.githubusercontent.com/0cbef4f0588bdf4e0603ca6460e45f8ad8c6fdba1339dde59957cd1722dc1156/68747470733a2f2f706f7365722e707567782e6f72672f666f726563686f2f796969322d726573742d6170692f646f776e6c6f616473)](https://packagist.org/packages/forecho/yii2-rest-api)[![Latest Unstable Version](https://camo.githubusercontent.com/bbc8f406790f7da95b3a5cb9c2cc40dc964e18886f51c81b8cefc741ea6143ed/68747470733a2f2f706f7365722e707567782e6f72672f666f726563686f2f796969322d726573742d6170692f762f756e737461626c65)](https://packagist.org/packages/forecho/yii2-rest-api)[![License](https://camo.githubusercontent.com/10ed139b603238c40f32b7e6f6b114e0ca8deaafead5f951ba833d3d6571a082/68747470733a2f2f706f7365722e707567782e6f72672f666f726563686f2f796969322d726573742d6170692f6c6963656e7365)](https://packagist.org/packages/forecho/yii2-rest-api)

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

[](#requirements)

The minimum requirement by this project template that your Web server supports PHP 7.2.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:

```
composer create-project --prefer-dist forecho/yii2-rest-api
cd
cp .env.example .env
php yii generate/key # optional
chmod 777 -R runtime/

```

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

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

```

### Install from GitHub

[](#install-from-github)

Accessing [Use this template](https://github.com/forecho/yii2-rest-api/generate) Create a new repository from yii2-rest-api

```
git clone xxxx
cd
cp .env.example .env
chmod 777 -R runtime/
```

You can then access the application through the following URL:

```
http://localhost//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

```

**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

Check out the packages
----------------------

[](#check-out-the-packages)

- [yiithings/yii2-doten](https://github.com/yiithings/yii2-doten)
- [sizeg/yii2-jwt](https://github.com/sizeg/yii2-jwt)
- [yiier/yii2-helpers](https://github.com/yiier/yii2-helpers)

Use
---

[](#use)

At this time, you have a RESTful API server running at `http://127.0.0.1:8000`. It provides the following endpoints:

- `GET /health-check`: a health check service provided for health checking purpose (needed when implementing a server cluster)
- `POST /v1/join`: create a user
- `POST /v1/login`: authenticates a user and generates a JWT
- `POST /v1/refresh-token`: refresh a JWT

Try the URL `http://localhost:8000/health-check` in a browser, and you should see something like `{"code":0,"data":"OK","message":"成功"}` displayed.

If you have `cURL` or some API client tools (e.g. [Postman](https://www.getpostman.com/)), you may try the following more complex scenarios:

```
# create a user via: POST /v1/join
curl -X POST -H "Content-Type: application/json" -d '{"username":"demo","email":"demo@email.com","password":"pass123"}' http://localhost:8000/v1/join
# should return like: {"code":0,"data":{"username":"demo","email":"demo@email.com","status":1,"created_at":"2020-07-18T16:38:11+08:00","updated_at":"2020-07-18T16:38:11+08:00","id":17},"message":"成功"}

# authenticate the user via: POST /v1/login
curl -X POST -H "Content-Type: application/json" -d '{"username": "demo", "password": "pass123"}' http://localhost:8000/v1/login
# should return like: {"code":0,"data":{"user":{"id":4,"username":"dem211o1","avatar":"","email":"de21mo1@mail.com","status":1,"created_at":"2020-07-17T23:49:39+08:00","updated_at":"2020-07-17T23:49:39+08:00"},"token":"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiIsImp0aSI6IllpaS1SRVNULUFQSSJ9.eyJpc3MiOiJodHRwOlwvXC9sb2NhbGhvc3QiLCJqdGkiOiJZaWktUkVTVC1BUEkiLCJpYXQiOjE1OTUwNjQ5NzIsImV4cCI6MTU5NTMyNDE3MiwidXNlcm5hbWUiOiJkZW0yMTFvMSIsImlkIjo0fQ.y2NSVQe-TQ08RnXnF-o55h905G9WHo6GYHNaUWlKjDE"},"message":"成功"}

# refresh a JWT
curl -X POST -H 'Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiIsImp0aSI6IllpaS1SRVNULUFQSSJ9.eyJpc3MiOiJodHRwOlwvXC9sb2NhbGhvc3QiLCJqdGkiOiJZaWktUkVTVC1BUEkiLCJpYXQiOjE1OTUwNjQ5NzIsImV4cCI6MTU5NTMyNDE3MiwidXNlcm5hbWUiOiJkZW0yMTFvMSIsImlkIjo0fQ.y2NSVQe-TQ08RnXnF-o55h905G9WHo6GYHNaUWlKjDE' http://localhost:8000/v1/refresh-token
# should return like: {"code":0,"data":{"user":{"id":4,"username":"dem211o1","avatar":"","email":"de21mo1@mail.com","status":1,"created_at":"2020-07-17T23:49:39+08:00","updated_at":"2020-07-17T23:49:39+08:00"},"token":"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiIsImp0aSI6IllpaS1SRVNULUFQSSJ9.eyJpc3MiOiJodHRwOlwvXC9sb2NhbGhvc3QiLCJqdGkiOiJZaWktUkVTVC1BUEkiLCJpYXQiOjE1OTUwNjQ5NzIsImV4cCI6MTU5NTMyNDE3MiwidXNlcm5hbWUiOiJkZW0yMTFvMSIsImlkIjo0fQ.y2NSVQe-TQ08RnXnF-o55h905G9WHo6GYHNaUWlKjDE"},"message":"成功"}
```

###  Health Score

29

—

LowBetter than 60% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity26

Limited adoption so far

Community14

Small or concentrated contributor base

Maturity46

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 96.4% of commits — single point of failure

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 ~2 days

Total

6

Last Release

2109d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/4c0612f70d09feb06ab5d24a31e0cc551f1ee547b42308c695e34d76181f18cf?d=identicon)[forecho](/maintainers/forecho)

---

Top Contributors

[![forecho](https://avatars.githubusercontent.com/u/1725326?v=4)](https://github.com/forecho "forecho (54 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (2 commits)")

---

Tags

yii2yii2-templateframeworkrestyii2project templatebasic

###  Code Quality

TestsCodeception

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/forecho-yii2-rest-api/health.svg)

```
[![Health](https://phpackages.com/badges/forecho-yii2-rest-api/health.svg)](https://phpackages.com/packages/forecho-yii2-rest-api)
```

###  Alternatives

[yii2mod/base

Base application template for Yii2

531.3k](/packages/yii2mod-base)

PHPackages © 2026

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