nikxphreaker/yii2-hiring-backend 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

nikxphreaker/yii2-hiring-backend

Composer 安装命令:

composer require nikxphreaker/yii2-hiring-backend

包简介

Yii 2 RESTful API

README 文档

README

Yii 2 RESTful API


++++++++++++++++++++++++++++++++++ Yii2 RESTful API ++++++++++++++++++++++++++++++++++ This API using template from Yii-api-template. This is a a REST API TEMPLATE with Yii2. This template use Yii2-Micro approach so it will be lightweight and easy to deploy.

Installation

Install composer.

Install with git

git clone https://github.com/nikophreaker/yii2-hiring-backend.git [app-name]

To directory [app-name]

composer install

Setup Database

Setup database configuration from config/db.php.

<?php
return [
    'components' => [
        'db' => [
            'class' => 'yii\db\Connection',
            'dsn' => 'mysql:host=localhost;dbname=your_db_name',
            'username' => 'root',
            'password' => '',
            'charset' => 'utf8',
        ],
    ],
];

Create new database


Import database hiring-backend.sql


Running API

yii serve

Directory Structure

Since this template use MicroFramework approach, directory structure might be a little bit different from Yii2.

  config/             contains application configurations
  controllers/        contains Web controller classes
  models/             contains model classes
  modules/            contains your rest-api versioning (based on modules)
  vendor/             contains dependent 3rd-party packages
  web/                contains the entry script and Web resources

Test Using Postman

Download Postman.

Auth Scenario

This template already have basic endpoint that you can use to start your REST-API. Such as:

Endpoint Type Usage
https://localhost:8080/session GET list all session created
https://localhost:8080/view?id={id} POST View a session
https://localhost:8080/login POST Login with username and password (stored 3 cookies include id, username & token)
https://localhost:8080/signup POST Signup with username, email and password
https://localhost:8080/logout This endpoint must be use if you want to clear your cookies
https://localhost:8080/v1/session GET List all session created (Must Login)
https://localhost:8080/v1/session/create POST Create a new session (Must Login)
https://localhost:8080/v1/session/update?id={id} PUT / PATCH Update a session (Must Login)
https://localhost:8080/v1/session/delete?id={id} DELETE Delete a session (Must Login)
https://localhost:8080/v1/session/view?id={id} GET View a session (Must Login)

This template use modules as versioning pattern. Every version of API saved in a module. This template already have v1 module, so it means if consumer want to use v1 API, it can access https://localhost:8080/v1/endpoint.

API Scenario

Creating User






Login User

Don't forget to save your token






Setting token

Change type authorization to Bearer Token and place your token to Token field






Create Session

Input key and values like an image






Edit Session

Set id on params from exist data Session and edit it throught `x-www-form-urlencoded`






Delete Session

Set id on params from exist data Session






Viewing Detail Session

You need token if you using v1 endpoint






List Session

You need token if you using v1 endpoint






Supported Authentication

This template support 3 most used authentication. (Actually it's not me who make it, Yii2 already support it all :D ).

  1. HTTP Basic Auth: the access token is sent as the username. This should only be used when an access token can be safely stored on the API consumer side. For example, the API consumer is a program running on a server.
  2. Query parameter: the access token is sent as a query parameter in the API URL, e.g., https://example.com/users?access-token=xxxxxxxx. Because most Web servers will keep query parameters in server logs, this approach should be mainly used to serve JSONP requests which cannot use HTTP headers to send access tokens.
  3. OAuth 2: the access token is obtained by the consumer from an authorization server and sent to the API server via HTTP Bearer Tokens, according to the OAuth2 protocol.

Access Token Management

This application manage token via cookie without storing to table or data in database. Access Token have certain expiration based on $tokenExpiration value. Default Token Expiration are in seconds.

public $tokenExpiration = 60 * 24 * 365; // in seconds

This cookies stored to your computer


if you want to delete all of this, you can using logout endpoint like this


API versioning

This template give you versioning scenario based on module application. In Yii2 a module are self-contained software units that consist of model, views, controllers and other supporting components. This template already have v1 module, it means all of endpoint for API v1 created in this module. When you publish a new API version (that break backward compatibility / BBC), you can create a new module. For more information create a module, you can visit this Yii2 Guide on Creating Module.

Screenshoot TEsting





nikxphreaker/yii2-hiring-backend 适用场景与选型建议

nikxphreaker/yii2-hiring-backend 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 0 次下载、GitHub Stars 达 1, 最近一次更新时间为 2021 年 01 月 27 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「framework」 「api」 「restful」 「yii2」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 nikxphreaker/yii2-hiring-backend 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 nikxphreaker/yii2-hiring-backend 我们能提供哪些服务?
定制开发 / 二次开发

基于 nikxphreaker/yii2-hiring-backend 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 0
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 14
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: BSD-3-Clause
  • 更新时间: 2021-01-27