PHPackages                             cebe/yii2-app-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. [API Development](/categories/api)
4. /
5. cebe/yii2-app-api

Abandoned → [php-openapi/yii2-app-api](/?search=php-openapi%2Fyii2-app-api)Project[API Development](/categories/api)

cebe/yii2-app-api
=================

Yii Framework Application Template for quickly building API-first applications.

2.3.1(1y ago)10843010[5 issues](https://github.com/php-openapi/yii2-app-api/issues)MITPHPPHP &gt;=7.1.0

Since Mar 22Pushed 1y ago6 watchersCompare

[ Source](https://github.com/php-openapi/yii2-app-api)[ Packagist](https://packagist.org/packages/cebe/yii2-app-api)[ RSS](/packages/cebe-yii2-app-api/feed)WikiDiscussions master Synced 2mo ago

READMEChangelog (9)Dependencies (10)Versions (11)Used By (0)

yii2-app-api
============

[](#yii2-app-api)

> OpenAPI Spec to API in 3, 2, 1... done!

Yii Framework Application Template for quickly building API-first applications.

Based on [yii2-openapi](https://github.com/php-openapi/yii2-openapi) (code generator) and [php-openapi](https://github.com/php-openapi/php-openapi) (specification reader and validator).

[![Latest Stable Version](https://camo.githubusercontent.com/94bd9a7c36f99fba87965561367118dbfd5ab2724df8d0778d11fd0a392d66cd/68747470733a2f2f706f7365722e707567782e6f72672f7068702d6f70656e6170692f796969322d6170702d6170692f762f737461626c65)](https://packagist.org/packages/php-openapi/yii2-app-api)[![Total Downloads](https://camo.githubusercontent.com/41a7339958aabc3684a4047cb7d4436ed6ad36ee7ccada31193c9c13d94d24a6/68747470733a2f2f706f7365722e707567782e6f72672f7068702d6f70656e6170692f796969322d6170702d6170692f646f776e6c6f616473)](https://packagist.org/packages/php-openapi/yii2-app-api)[![License](https://camo.githubusercontent.com/c680b25f1a861c5eb6b9deed7eccb4674bd099cd1b9f003adefbbefd15cbcfb7/68747470733a2f2f706f7365722e707567782e6f72672f7068702d6f70656e6170692f796969322d6170702d6170692f6c6963656e7365)](https://packagist.org/packages/php-openapi/yii2-app-api)

Demo
----

[](#demo)

[![asciicast](https://camo.githubusercontent.com/7ea0d9dca190ba4e8ea33691c0d8c2502f29d7605c65708f2a165039dc81e47a/68747470733a2f2f61736369696e656d612e6f72672f612f47536e5a46654c30626541774c766268496e35306f564939772e737667)](https://asciinema.org/a/GSnZFeL0beAwLvbhIn50oVI9w)

Overview
--------

[](#overview)

This application template does not contain any useful code, it only provides the [directory structure](#structure) for your API project. All the code is generated from an [OpenAPI](https://www.openapis.org/about) API description file.

When working with this template you follow the [API Design-First Approach](https://apisyouwonthate.com/blog/api-design-first-vs-code-first). So to get started building an API with this application template you need an API description first. If you don't have one yet, you might want to check the following resources first:

- [OpenAPI 3.0 tutorial](https://idratherbewriting.com/learnapidoc/pubapis_openapi_tutorial_overview)
- [OpenAPI Specification Version 3.0.2](http://spec.openapis.org/oas/v3.0.2)

If you have an OpenAPI description, you can continue with the next steps:

1. [Setup](#setup)
2. [Generate Code](#generate-code)

More Docs and Guides can be found in [/docs](/docs/README.md).

Setup
------

[](#setup-)

There are two different ways:

- PHP directly on your machine
- Using Docker

### PHP directly

[](#php-directly)

Having PHP and a database server installed on your machine, you can run the following commands:

```
composer create-project php-openapi/yii2-app-api my-api
cd my-api
cp env.php.dist env.php
cp config/components-ENV.local.php config/components-dev.local.php

```

You need to adjust `config/components-dev.local.php` to configure your database connection.

After that, run `make start` and `make stop` to control the PHP webservers for API and backend.

You may use `XDEBUGW=1` to enable xdebug for the webserver, e.g. `make XDEBUGW=1 start`.

You can now continue with [generating code](#generate-code).

### Using Docker

[](#using-docker)

You need [Docker](https://docs.docker.com/install/) and [Docker Compose](https://docs.docker.com/compose/install/) installed.

Create the repository:

```
composer create-project php-openapi/yii2-app-api my-api

```

For the easiest way you need GNU make, then run:

```
make start-docker

```

This uses `docker-compose` to start docker containers for the API and the backend including a database.

You can now continue with [generating code](#generate-code).

> Note: If you don't have GNU make, you need to copy the configuration files as in the PHP directly section, then run:
>
> ```
> cp docker-compose.override.dist.yml docker-compose.override.yml
> docker-compose up -d
> docker-compose exec backend-php sh -c 'cd /app && composer install'
>
> ```

Generate Code
--------------

[](#generate-code-)

At this point you can start generating your API code to play with it by following the instructions below. If you'd like to start a real project instead of just playing around you can find more detailed documentation in [docs/README.md](docs/README.md) specifically the ["Getting Started"-Section](docs/getting-started.md).

### Console

[](#console)

> Tip: If you use Docker, run `make cli` before running any of these commands.

Run `./yii gii/api` to generate your API code. The `--openApiPath` parameter specifies the path to your OpenAPI spec file. The following example will generate API code for the [OpenAPI petstore example](https://github.com/OAI/OpenAPI-Specification/blob/3.0.2/examples/v3.0/petstore-expanded.yaml).

```
./yii gii/api --openApiPath=https://raw.githubusercontent.com/OAI/OpenAPI-Specification/3.0.2/examples/v3.0/petstore-expanded.yaml

```

> Note: If the OpenAPI spec file is present locally on the file system, then `openApiPath` must be specified as an absolute path, relative paths will not work correctly. On UNIX based OS it must start with `/`. Example: `/home/user/documents/MyProjectOpenAPISpec.yml`

Run `./yii gii/api --help` for a list of configuration options. You may also adjust the configuration in `config/gii-generators.php`.

Then set up the database:

```
./yii migrate/up
./yii faker

```

### Web

[](#web)

To use the web generator, open  and select the `REST API Generator`.

[![Gii - REST API Generator](docs/img/gii-generator.png)](docs/img/gii-generator.png)

Enter the path or URL to the "OpenAPI 3 Spec file", e.g. `https://raw.githubusercontent.com/OAI/OpenAPI-Specification/3.0.2/examples/v3.0/petstore-expanded.yaml`.

Click "Preview":

[![Gii - REST API Generator - Generated files](docs/img/gii-generator-files.png)](docs/img/gii-generator-files.png)

Click "Generate" to generate API files.

Then set up the database by running the following commands on the command line:

```
./yii migrate/up
./yii faker

```

Try it
------

[](#try-it)

```
cd api
make start

```

Your API is now available at `http://localhost:8337/`. Try to access an endpoint of your spec via `curl`:

```
$ curl http://localhost:8337/pets
[
    {
        "name": "Eos rerum modi et quaerat voluptatibus.",
        "tag": "Totam in commodi in est nisi nihil aut et."
    },
    {
        "name": "Voluptas quia eos nisi deleniti itaque aspernatur aspernatur.",
        "tag": "Temporibus id culpa dolorem sequi aut."
    },
    {
        "name": "Facere aut similique laboriosam omnis perferendis et.",
        "tag": "Quo harum quo et ea distinctio non quam."
    },
    ...
]

```

Linting the OpenAPI specification
---------------------------------

[](#linting-the-openapi-specification)

You can run a linter to check the validity of your OpenAPI specification file:

```
make lint-js  # run spectral lint
make lint-php # run php-openapi validate
make lint     # run both of the above commands

```

You can find more information on spectral at .

Application structure
----------------------

[](#application-structure-)

This application template consists of 3 application tiers:

- `api`, contains the Yii application for the REST API.
- `console`, contains the Yii application for console commands, cronjobs or queues (`yii` command).
- `backend`, contains the Yii application for a CRUD backend on the API data.

The following list explains the directory structure in more detail:

- `api/` - API application tier

    - `config/` - configuration for API tier
        - `url-rules.php` - custom URL rules
        - `url-rules.rest.php` - URL rules **generated** from OpenAPI Description
        - `components.php` - application components
        - `app.php` - Yii application config (+ overrides for different environments `app-*.php`)
    - `controllers/` - Controller classes **generated** from OpenAPI Description
    - `web/` - public web directory for API application
- `backend/` - Backend application tier

    - `config/` - configuration for Backend tier
        - `components.php` - application components
        - `app.php` - Yii application config (+ overrides for different environments `app-*.php`)
    - `controllers/` - Controller classes
    - `views/` - View files
    - `web/` - public web directory for Backend application
- `common/` - common code files

    - `models/` - model classes **generated** from OpenAPI Description
    - `migrations/` - database migrations **generated** from OpenAPI Description
- `config/` - Common configuration for all application tiers

    - `components.php` - Yii application components (+ overrides for different environments `components-*.php`)
    - `env.php` - Environment setup (YII\_DEBUG, YII\_ENV, path aliases, composer autoloader)
    - `events.php` - Class wide event listeners
    - `gii-generators.php` - configuration for the Gii code generator (allows to set default values for the ApiGenerator)
    - `params.php` - Configuration for `Yii::$app->params`
- `console/` - Console application tier

    - `config/` - configuration for Console tier
        - `components.php` - application components
        - `app.php` - Yii application config (+ overrides for different environments `app-*.php`)
- `logs/` - log files
- `runtime/` - temporary runtime files

Development
===========

[](#development)

Below commands are helpful while developing this project:

```
./yii gii/api --openApiPath=/app/openapi/schema.yaml --generateMigrations=0  --generateControllers=0 --generateUrls=0

./yii gii/api --openApiPath=/app/openapi/schema.yaml --generateMigrations=1  --generateControllers=0 --generateUrls=0 --generateModels=0 --generateModelFaker=0
```

Support
=======

[](#support)

**Need help with your API project?**

Professional support, consulting as well as software development services are available:

Development of this library is sponsored by [cebe.:cloud: "Your Professional Deployment Platform"](https://cebe.cloud).

###  Health Score

37

—

LowBetter than 82% of packages

Maintenance32

Infrequent updates — may be unmaintained

Popularity28

Limited adoption so far

Community16

Small or concentrated contributor base

Maturity61

Established project with proven stability

 Bus Factor1

Top contributor holds 80% 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 ~237 days

Recently: every ~149 days

Total

9

Last Release

702d ago

Major Versions

0.9.0-beta → 1.0.02019-06-26

1.1.0 → 2.0.02022-05-18

### Community

Maintainers

![](https://www.gravatar.com/avatar/261a6249c6f605f3956a2fae40fbb813f6b2e1e6f2bf806180c851a965426e54?d=identicon)[cebe](/maintainers/cebe)

---

Top Contributors

[![cebe](https://avatars.githubusercontent.com/u/189796?v=4)](https://github.com/cebe "cebe (68 commits)")[![SOHELAHMED7](https://avatars.githubusercontent.com/u/6770119?v=4)](https://github.com/SOHELAHMED7 "SOHELAHMED7 (14 commits)")[![siggi-k](https://avatars.githubusercontent.com/u/43443582?v=4)](https://github.com/siggi-k "siggi-k (3 commits)")

---

Tags

apihacktoberfestopenapiopenapi3yii2yii2-application-template

###  Code Quality

TestsCodeception

### Embed Badge

![Health badge](/badges/cebe-yii2-app-api/health.svg)

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

###  Alternatives

[dotzero/yii2-amocrm

Расширение для Yii Framework 2 реализующее клиент для работы с API amoCRM

1639.7k](/packages/dotzero-yii2-amocrm)[conquer/services

Yii2 soap wsdl web services

1632.5k](/packages/conquer-services)[skeeks/yii2-google-api

Component for work with google api based on google/apiclient

1243.1k1](/packages/skeeks-yii2-google-api)[apexwire/yii2-restclient

Tools to use API as ActiveRecord for Yii2

143.5k](/packages/apexwire-yii2-restclient)

PHPackages © 2026

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