|
4 | 4 |
|
5 | 5 | Yii Framework Application Template for quickly building API-first applications. |
6 | 6 |
|
| 7 | +## Overview |
| 8 | + |
| 9 | +This application template consists of 3 application tiers: |
| 10 | + |
| 11 | +- `api`, contains the Yii application for the REST API. |
| 12 | +- `console`, contains the Yii application for console commands, cronjobs or queues. |
| 13 | +- `backend`, contains the Yii application for a CRUD backend on the API data. |
| 14 | + |
| 15 | + |
7 | 16 | ## Setup |
8 | 17 |
|
9 | 18 | git clone https://github.com/cebe/yii2-app-api my-api |
10 | 19 | cd my-api |
| 20 | + cp env.php.dist env.php |
11 | 21 | composer install |
12 | 22 |
|
13 | | -## Overview |
| 23 | +## Generate Code |
14 | 24 |
|
15 | | -This application consists of 3 parts: |
| 25 | +### Console |
16 | 26 |
|
17 | | -- `api`, contains the Yii application for the REST API. |
18 | | -- `console`, contains the Yii application for console commands, cronjobs or queues. |
19 | | -- `backend`, contains the Yii application for a CRUD backend on the API data. |
| 27 | +Run `./yii gii/api` to generate your API code. The `--openApiPath` parameter specifies the path to your OpenAPI |
| 28 | +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). |
| 29 | + |
| 30 | + ./yii gii/api --openApiPath=https://raw.githubusercontent.com/OAI/OpenAPI-Specification/3.0.2/examples/v3.0/petstore-expanded.yaml |
| 31 | + |
| 32 | +Run `./yii gii/api --help` for a list of configuration options. You may also adjust the configuration in `config/gii-generators.php`. |
| 33 | + |
| 34 | +Then set up the database: |
| 35 | + |
| 36 | + ./yii migrate/up |
| 37 | + ./yii faker |
| 38 | + |
| 39 | +### Web |
| 40 | + |
| 41 | +To use the web generator, start the backend server: |
| 42 | + |
| 43 | + cd backend |
| 44 | + make start |
| 45 | + |
| 46 | +open `http://localhost:8338/gii` and select the `REST API Generator`. |
| 47 | + |
| 48 | + |
| 49 | + |
| 50 | +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`. |
| 51 | + |
| 52 | +Click "Preview": |
| 53 | + |
| 54 | + |
| 55 | + |
| 56 | +Click "Generate" to generate API files. |
| 57 | + |
| 58 | +Then set up the database by running the following commands on the command line: |
20 | 59 |
|
| 60 | + ./yii migrate/up |
| 61 | + ./yii faker |
21 | 62 |
|
0 commit comments