blurrywindows / yii2-api-kit
Yii 2 based kit that may be used to quickly start building an api from it.
Installs: 1
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 3
Forks: 1
Open Issues: 0
Type:project
Requires
- php: >=5.6.0
- vlucas/phpdotenv: ^2.4
- yiisoft/yii2: ~2.0.5
- yiisoft/yii2-bootstrap: ~2.0.0
- yiisoft/yii2-swiftmailer: ~2.0.0
Requires (Dev)
- codeception/codeception: ^2.3.3
- codeception/specify: ~0.4.3
- codeception/verify: ~0.3.1
- yiisoft/yii2-debug: ~2.0.0
- yiisoft/yii2-faker: ~2.0.0
- yiisoft/yii2-gii: ~2.0.0
This package is not auto-updated.
Last update: 2021-11-27 13:06:39 UTC
README
Heavily inspired by trntv/yii2-starter-kit, this API kit may be used to quickly start building your Yii2-based API and not waste any time on initializing your project.
This kit is in development. Please do not use it yet! Would you like to contribute?
TABLE OF CONTENTS
FEATURES
- Migrations for initial database with user-functionality
- AutoController which generates ActiveRecords models and API documentation based on apidoc
- Pre-created account functionality (register & login)
- Authentication based on HTTP-header
- Json support
- dotenv support
- Test-ready
- blurrywindows/yii2-key-helper functionality
REQUIREMENTS
- PHP >= 5.6.0
- Composer >= 1.1.2 (https://getcomposer.org/)
- Node.js >= 8.1.0 (https://nodejs.org/en/)
INSTALLATION
composer create-project blurrywindows/yii2-api-kit
CONFIGURATION
Please follow these instructions carefully to quickly start building your own API. The instructions must be executed in the order in which they are presented here to prevent errors.
Composer
- Install all required Composer packages (
composer install
). - When deploying to production, only install production packages (
composer install --no-dev
).
Node.js
- Install all required Node.js packages (
npm install
). - When deploying to production, only install production packages (
npm install --production
).
Database
- Create a database you will use for your API.
- Make sure that a user with read/write access exists for this database.
Environment
- Rename
.env.demo
to.env
in your project root and alter the variables to your current environment. - Make sure that the
ENTRY_URL
variable has a trailing slash (/).
Migrate
- Migrate (let Yii create initial database tables) using the
./yii migrate
command. - If this command doesn't work, try adding
php
to the command:php ./yii migrate
.
Webserver
- Follow the instruction in the Yii2 guide to make your API available to the internet (or to your local development environment).
TESTING
This api-kit is test-ready.
The controllers and models are included in both acceptance and unit testing based on Codeception.
They are located in /tests
. To execute the tests, run ./vendor/bin/codecept run
.
CONSOLE COMMANDS
AutoController
These actions should normally not run on a production server. The actions mentioned here generate files and data that may be used in development or testing. When executing these actions in a production environment, the controller will generate a warning prompt that you may override.
./yii auto/all
Executes all the actions in the AutoController.
./yii auto/gii-models
Generates ActiveRecords for all the tables in your database in the ./models
folder.
It automatically overwrites the ActiveRecords if they exist.
The ActiveRecords are named Base[Tablename]
and extend BaseActiveRecord
.
It also creates a class [Tablename]
which extends Base[Tablename]
for custom code, extra validation rules, etc.
The [Tablename]
class will not be overridden when executing the action again.
./yii auto/apidoc
Generates API documentation based on apidoc from the comments in the ./controllers
folder.
It outputs the documentation in the Git-ignored folder ./web/apidoc
.
You may include this folder in Git manually if you want to export the documentation to a production server.
Please note, apidoc is a dev-dependency in Node.js. It will only be installed when using the npm install
command.
HOW TO CONTRIBUTE
You may contribute in any way you want, but please contact me beforehand to prevent merge-conflicts by creating an issue.
ISSUES
If you have any questions or experience any issues with this kit, please submit an issue.