vince-scarpa/responsibleapi
Composer 安装命令:
composer require vince-scarpa/responsibleapi
包简介
关键字:
README 文档
README
ResponsibleAPI RESTful API
Responsible API is a secure PHP RESTful application that allows easy HTTP requests from
external requests fused by Json Web Tokens (JWT).
ResponsibleSDK is recommended to connect to the ResponsibleAPI\
Development
Version 1.4
This repo is open for contributions.
Features include:
-
JWT
- to sign each request
-
Rate limiting
- to limit requests to a timed window frame and options to allow unlimited requests
-
The Leaky bucket algorithm
- used for request throttling
Requirements
PHP 7.x
Composer
ResponsibleSDK [recommended]
Installation
Install composer if not already
https://getcomposer.org/doc/00-intro.md
Install ResponsibleSDK [recommended for quick example]
https://github.com/vince-scarpa/responsibleSDK
$ cd <responsible sdk directory>
$ git clone https://github.com/vince-scarpa/responsibleAPI.git
$ composer install
Setup
In order for the ResponsibleAPI to initiate we need to add some basic configurations
- Import the example sql file
- Use or Create a
.configfile
Setup your storage
The ResponsibleAPI uses MySQL as Database storage, run the supplied responsible.sql file to install the required tables
Setup a config file
If you didn't get a .config file shipped in this repo then you'll need to create one.
In the repo root directory run the following or anyway you know to create and write to files
$ cd <responsible sdk directory>
$ mkdir config
$ touch config/.config
Your file structure should look like this
- responsibleAPI
- config
- .config
- src
- (...)
- config
Edit your new .config file and paste the below code, change all credentials to reflect your storage
Note: The MASTER_KEY is the global "secret key" for system use to sign requests.
To generate a strong secret I recommend using a strong password generator, this has no length limit but do note you probably want to stick to 32bytes. The only tested characters are;
ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789`-=~!@#$%^&*()_+,./?;[]{}\|
DB_TYPE = 'mysql'
DB_PORT = '3306'
DB_NAME = '<YOUR_DB_NAME>'
DB_USER = '<YOUR_DB_USER_NAME>'
DB_PASSWORD = '<YOUR_DB_PASSWORD>'
DB_HOST = '<YOUR_DB_HOST>'
MASTER_KEY = '<YOUR_MASTER_SECRET>'
Basic usage
Setting up our API server
<?php /** * Composer Autoloader */ require __DIR__ . '/responsibleAPI/vendor/autoload.php'; /** * Load Responsible API core */ require __DIR__ . '/responsibleAPI/src/responsible.php'; /** * Load Responsible API core */ use responsible\responsible; // Initiate the API with no options, let ResponsibleAPI take care of all defaults $responsible = responsible::API(); // Print the response $responsible::response(true);
What does the above example give us? well, nothing really...
Just a permissions denied message and a server waiting for real requests.
To access the ResponsibleAPI server via requests you'll need to run the ResponsibleSDK, this can be found @
https://github.com/vince-scarpa/responsibleSDK or any other HTTP request method you're comfortable with
Options
Add options
$options = array( /** * Output type */ 'requestType' => 'json', // json, array, object, xml, html, debug /** * Headers */ // Max control age header "Access-Control-Max-Age" 'maxWindow' => 86400, // Defaults to 3600 (1 hour) /** * Add custom headers * Custom headers must be create in the below format * nothing will happen if not, no errors no added headers */ 'addHeaders' => array( ['x-my-new-responsible-api', '1.2'], ), /** * JWT refresh options */ 'jwt' => [ 'leeway' => 10, // n seconds leeway for expiry 'issuedAt' => time(), 'expires' => time() + 300, 'notBeFor' => 'issuedAt', // issuedAt, or e.g (time()+10) ], /** * Rate limiter */ 'rateLimit' => 1000, // API call Limit 'rateWindow' => 'MINUTE', // Window timeframe SECOND, MINUTE, HOUR, DAY, [CUSTOM/ A POSITIVE INTEGER] /** * --- Warning --- * * This will override any rate limits * No maximum calls will be set and the Responsible API * can run for as many calls and as often as you like * This should only be used for system admin calls */ 'unlimited' => false, // Unlimited API calls true / false or don't include to default to false /** * Leaky bucket * */ 'leak' => true, // Use token bucket "defaults to true" 'leakRate' => 'default', // slow, medium, normal, default, fast or custom positive integer /** * Customise a middle ware class directory */ 'classRoute' => [ 'directory' => __DIR__ . '/src/service/endpoints', // ABSOLUTE_PATH_STRING, __DIR__ ect..., 'namespace' => 'backmagic', ] ); $responsible = responsible::API($options);
vince-scarpa/responsibleapi 适用场景与选型建议
vince-scarpa/responsibleapi 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 11.22k 次下载、GitHub Stars 达 2, 最近一次更新时间为 2019 年 08 月 07 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「php」 「api」 「jwt」 「responsibleAPI」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 vince-scarpa/responsibleapi 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 vince-scarpa/responsibleapi 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 vince-scarpa/responsibleapi 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A simple library to decode and parse Apple Sign In client tokens.
A PSR-7 compatible library for making CRUD API endpoints
JWT API authentication driver (Guard) for Laravel.
Laravel JWT auth service package
A Laravel 6 API Boilerplate to create a ready-to-use REST API. User Authentication using JWT.
Alfabank REST API integration
统计信息
- 总下载量: 11.22k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 3
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2019-08-07