All Projects → forecho → yii2-rest-api

forecho / yii2-rest-api

Licence: BSD-3-Clause license
Yii 2 REST API Project Template

Programming Languages

PHP
23972 projects - #3 most used programming language
Batchfile
5799 projects
shell
77523 projects

Projects that are alternatives of or similar to yii2-rest-api

yii2-docker-app-advanced
Yii 2 Advanced Project Template under docker and docker-compose
Stars: ✭ 25 (-30.56%)
Mutual labels:  yii2, yii2-template
yii2-basic-firestarter
This is a pimped up basic yii2 template ❤️. It's a firestarter 🔥
Stars: ✭ 35 (-2.78%)
Mutual labels:  yii2, yii2-template
yii2-material-theme
Material Theme for Yii2
Stars: ✭ 15 (-58.33%)
Mutual labels:  yii2, yii2-template
yii2-notifications
This Yii2 extension provides support for sending notifications across a variety of delivery channels, including mail, SMS, Slack, Telegram etc.
Stars: ✭ 62 (+72.22%)
Mutual labels:  yii2
yii2-render-many
Trait for Yii Framework 2
Stars: ✭ 14 (-61.11%)
Mutual labels:  yii2
yii2-pgsql
Improved PostgreSQL schemas for Yii2
Stars: ✭ 34 (-5.56%)
Mutual labels:  yii2
yii2-app-template
Yii2 App Project Template
Stars: ✭ 25 (-30.56%)
Mutual labels:  yii2-template
yii2-merchant
Payment merchants extension for Yii2
Stars: ✭ 17 (-52.78%)
Mutual labels:  yii2
yii2-vue-admin
Yii2 Vue Admin Template
Stars: ✭ 22 (-38.89%)
Mutual labels:  yii2
funboot
基于Yii2的Saas快速开发平台,内置多商户并内置商城、论坛、CMS等子系统。Yii2/Mysql/Mongodb/Redis/Elasticsearch/SnowFlake雪花算法ID生成 RBAC动态权限 数据权限 定时任务 日志/消息 代码生成Gii升级
Stars: ✭ 273 (+658.33%)
Mutual labels:  yii2
yii2-cashier
Yii2 Cashier provides an interface to Stripe's subscription billing services.
Stars: ✭ 43 (+19.44%)
Mutual labels:  yii2
yii2-config-kit
Configuration kit for Yii applications
Stars: ✭ 24 (-33.33%)
Mutual labels:  yii2
yii2-flatpickr
Datetime picker widget for Yii2 framework
Stars: ✭ 17 (-52.78%)
Mutual labels:  yii2
yii2-newsletter
Module for saving user contacts from newsletter form to database
Stars: ✭ 17 (-52.78%)
Mutual labels:  yii2
yii2-jwt-tools
An easy way to configure JWT authentication and validation on Yii Framework 2 Projects
Stars: ✭ 22 (-38.89%)
Mutual labels:  yii2
yii2-inertia
The Yii 2 server-side adapter for Inertia.js.
Stars: ✭ 52 (+44.44%)
Mutual labels:  yii2
luya-module-cms
The LUYA CMS module provides a full functional CMS for adding contents based on blocks.
Stars: ✭ 28 (-22.22%)
Mutual labels:  yii2
ar-search
Provides unified search model for Yii ActiveRecord
Stars: ✭ 31 (-13.89%)
Mutual labels:  yii2
yii2-at-least-validator
Makes one or more attributes mandatory inside a set of attributes.
Stars: ✭ 28 (-22.22%)
Mutual labels:  yii2
behavior-trait
Allows handling events via inline declared methods, which can be added by traits
Stars: ✭ 18 (-50%)
Mutual labels:  yii2

Yii 2 REST API Project Template


Yii 2 REST API Project Template is a skeleton Yii 2 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 Lint Code Coverage Scrutinizer Code Quality Latest Stable Version Total Downloads Latest Unstable Version License

REQUIREMENTS

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

INSTALLATION

Install via Composer

If you do not have Composer, you may install it by following the instructions at getcomposer.org.

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

composer create-project --prefer-dist forecho/yii2-rest-api <rest-api>
cd <rest-api>
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/<rest-api>/web/

Install from GitHub

Accessing Use this template Create a new repository from yii2-rest-api

git clone xxxx
cd <rest-api>
cp .env.example .env
chmod 777 -R runtime/

You can then access the application through the following URL:

http://localhost/<rest-api>/web/

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)
  • The default configuration uses a host-volume in your home directory .docker-composer for composer caches

Check out the packages

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), 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":"[email protected]","password":"pass123"}' http://localhost:8000/v1/join
# should return like: {"code":0,"data":{"username":"demo","email":"[email protected]","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":"[email protected]","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":"[email protected]","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":"成功"}
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].