kartenmacherei / rest-framework
用于创建RESTful Web服务的微框架
3.0.1
2023-10-09 10:32 UTC
Requires
- php: >=7.1.0
- kartenmacherei/kam-newrelic: ^1.0
Requires (Dev)
- phpunit/phpunit: ^6.3
This package is auto-updated.
Last update: 2024-09-09 13:16:57 UTC
README
该框架的目标是在遵守我们非常严格的编码规范的同时,快速启动新的RESTful服务。这特别意味着应避免任何类型的魔法。
基本概念
组件
RestResource
- 提供了一种可以与
URI
进行匹配的Pattern
- 通过实现像
SupportsGetRequests
这样的接口来支持HTTP动词 - 通过显式方法如
getPostCommand()
或getQuery()
返回Action
对象
ResourceRouter
- 持有其负责的所有
RestResource
对象的引用 - 在
canRoute()
中确定它是否负责路由给定的URL - 在
doRoute()
中返回一个RestResource
命令
- 改变资源的状态(如创建或更新)
查询
- 不会改变资源的状态,仅返回现有数据。
使用框架
要求
- Composer
- PHP 7.0+
将框架添加到你的composer.json
"require": {
"kartenmacherei/rest-framework": "dev-master"
}
将你的代码连接到框架
// create a request $request = Request::fromSuperGlobals(); // create config object // 'app-name' will be used as newrelic appname, if monitoring was enabled // bool $enableMonitoring if true, framework will set newrelic transaction name based on mapping // array $transactionMapping, class name to transaction name mapping array for each action. If action was not set, fallback is transaction_name_was_not_set $config = new Config('app-name', $enableMonitoring, $transactionNamesMapping); // create a new instance of the framework $framework = Framework::createInstance($config); // register a RestResource Router $framework->registerResourceRouter(new BasketResourceRouter()); // let the framework process the request $response = $framework->run($request); // send the response to the client $response->flush();
查看https://github.com/kartenmacherei/rest-framework-example以获取一个工作示例。
许可证
本软件根据MIT许可证的条款进行许可。请参阅LICENSE.md以获取完整的许可证。