承接 slavikme/slim-api-skeleton 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

slavikme/slim-api-skeleton

Composer 安装命令:

composer create-project slavikme/slim-api-skeleton

包简介

A skeleton project based on Slim Framework 2. Start developing API applications instantly.

README 文档

README

Open Issues Stars on GitHub Forks on GitHub Sponsor by PayPal GitHub license

Slim API Skeleton

A skeleton project based on Slim Framework 2, which targets for developers to start an API application instantly.

NOTE: This is an alpha version and it is currently in a developmnet process

Contributions are welcomed!

Implemented

  • Composer create-project functionality
  • Application configuration in a single file
  • Relational Database support
  • Authentication support based on API token with the following user information sources
    • From relational database
  • Customizable API token expiration time with predefined default and maximum values
  • Routing settings in a single file
    • Define an HTTP Method or array of methods
    • Route with parameters
    • Controller class and class method
    • Define conditions to parameters
  • Controller classes support

TODO

  1. Add authentication support based on API key with the following user information sources
  2. From Configuration File
  3. From Big Data/NoSQL records
  4. Add authorization support
  5. Add logging
  6. Add Caching mechanism
  7. Auto-doc generator

Recommendations

It is strongly recommended to install this framework on UNIX-based operating systems (Linux or Macintosh), as it is much easier and much faster to make everything work smoothly.
Of course you can make it work on Windows, but I would recommend to save your valuable time and prevent unnecessary headache.
In this documentation, I will explain how to make it work on UNIX-based system and not on Windows. If you still want to install it on Windows, I'm sorry, but you'll have to figure it out by yourself.
Note: You can always run a VM (Virtual Machine) with a Linux, using a VirtualBox or any other virtual machine to install a Linux OS. And then proceed with this documentation on your newly installed Linux on your VM.

Requirements

  • Apache 2.x (or if you prefer Nginx, you will have to make sure that the Authorization header is passed in to your PHP application as described in the public/.htaccess file. Also, you should rewrite everything to point to the public/app.php file)
  • PHP 5.6+
  • MySQL 5.5+
  • Composer 0.9+ (installation instructions)

Installation

INCOMPLETE!

  1. Open a command line interface.

  2. Navigate to the path where you want to create the project directory.

  3. Run the following command:

    composer create-project slavikme/slim-api-skeleton
    
  4. Follow the instructions.

  5. Create a Virtual Host with the hostname slimapi.local and point the base directory to the public directory.

Usage

INCOMPLETE!

Just call any path defined in the routes.yml, with the token received from the Authentication process below, in the Authorization request header along with the phrase Bearer. For example:

GET / HTTP/1.1
Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ0aW1lIjoxNDM5MDQzMDkxLCJleHB0aW1lIjogMTQzOTA0NDI5MSwidXNlciI6eyJpZCI6IjEiLCJ1c2VybmFtZSI6ImVhc3Rlci1lZ2ciLCJyb2xlIjoiQURNSU4iLCJuYW1lIjoiQ29uZ3JhdHMsIE5vdyBZb3UgVW5kZXJzdGFuZCBUaGUgSldUIFByb3RvY29sIiwiZW1haWwiOiJnb29kQGpvYi5jb20iLCJzdGF0dXMiOiIxIiwibGFzdGxvZ2luX3RpbWUiOiIyMDE1LTA4LTA2IDE3OjEwOjA0In19.4YHynX_j2mhXLWGgLTHTf6IgY5HwHBIzl8mUqQa8vUw
Host: api.slim.local
Connection: close

Authentication

The authentication method implemented in this framework is JWT (JSON Web Tokens).
A special authentication route has been implemented and is ready to use out of the box.

Request

Use the route /auth with the method POST to authenticate by sending mandatory credentials username and password, and optional credential remember_minutes in the body of the request wrapped in form or JSON formats (both are supported equally).
The request body should be sent as follows:

JSON Format
{
    "username": "john",
    "password": "Snow123",
    "expiration": "45 minutes"
}

Note: JSON format requests must be sent along with the Content-Type: application/json header property in the request headers in order to make it work.

Form Format
username=john&password=Snow123&expiration=45%20minutes
Request Parameters
  • username - The username from the tbl_user table (See the Database - User Table section).
  • password - The username from the tbl_user table (See the Database - User Table section).
  • expiration - A date/time string when the token expires (The same value as the PHP strtotime() function accepts in its first argument). This parameter is optional and may not be sent. If this parameter will not be sent, the default value will be used as defined within the auth.lifetime property located in config/parameters.yml file.

Response

The response depending on the request. If the authentication route has been requested without different, incorrect or invalid parameters, or without any username-password match in the tbl_user table, or user's status is equal or lower than 0, the response will be always 401 as an HTTP status code with the following JSON data in the body:

{
    "error": true,
    "msg": "Unauthorized access",
    "status": 401
}

Otherwise, the authentication should succeed with the response status code 200 and response body similar to the following:

{
    "error": false,
    "token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ0aW1lIjoxNDM5MDQzMDkxLCJleHB0aW1lIjogMTQzOTA0NDI5MSwidXNlciI6eyJpZCI6IjEiLCJ1c2VybmFtZSI6ImVhc3Rlci1lZ2ciLCJyb2xlIjoiQURNSU4iLCJuYW1lIjoiQ29uZ3JhdHMsIE5vdyBZb3UgVW5kZXJzdGFuZCBUaGUgSldUIFByb3RvY29sIiwiZW1haWwiOiJnb29kQGpvYi5jb20iLCJzdGF0dXMiOiIxIiwibGFzdGxvZ2luX3RpbWUiOiIyMDE1LTA4LTA2IDE3OjEwOjA0In19.4YHynX_j2mhXLWGgLTHTf6IgY5HwHBIzl8mUqQa8vUw",
    "status": 200
}
Response Referense
  • status - The status of the response, mostly is the response status code. Always included in the response.
  • error - Indicates whether an error has occurred for any possible reason. This will return true on error along with msg parameter, otherwise will return false. Always included in the response.
  • msg - A string that explains why the error has been occurred. Should always be included if error is true.
  • token - A valid JWT authentication token, used for authenticated requests in this API (Usage explained in the Request - Authenticated Usage section).

Authenticated Usage

TODO: Complete this section

Database

User Table

The following code used to create a new user table manually.

CREATE TABLE `tbl_user` (
    `id` int(11) NOT NULL AUTO_INCREMENT,
    `username` varchar(50) NOT NULL,
    `password` varchar(255) NOT NULL,
    `role` varchar(50) NOT NULL,
    `name` varchar(255) DEFAULT NULL,
    `email` varchar(255) DEFAULT NULL,
    `create_time` datetime DEFAULT NULL,
    `update_time` datetime DEFAULT NULL,
    `status` tinyint(4) NOT NULL DEFAULT '1',
    `lastlogin_time` datetime DEFAULT NULL,
    PRIMARY KEY (`id`),
    UNIQUE KEY `username_UNIQUE` (`username`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;

slavikme/slim-api-skeleton 适用场景与选型建议

slavikme/slim-api-skeleton 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 58 次下载、GitHub Stars 达 2, 最近一次更新时间为 2015 年 08 月 03 日, 在 PHP 生态内属于活跃度较高的组件。

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

围绕 slavikme/slim-api-skeleton 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

  • Stars: 2
  • Watchers: 5
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-08-03