restful / wrapper
RESTful api 的 PHP 封装
v1.3.3
2014-04-03 00:49 UTC
Requires
- php: >=5.3.0
This package is not auto-updated.
Last update: 2024-09-28 12:58:46 UTC
README
一个简单的 PHP RESTful api 封装。
代码示例
$restful = new RESTful('https://<yourcompany>.com/<path>/<to>/<resource>', '<token>');
$restful->post($path, $data);
默认 Content-Type
默认的 Content-Type 是 application/json
要更改默认 Content-Type
$restful->setContentType(<newContentType>);
默认 URL 路径配置和身份验证
默认 URL 路径是 <baseURI>/<path_to_data>/<token>/
如果您需要向 URL 路径添加特殊配置
$restful->setPathConfiguration(<newPathConfiguration>);
示例
Firebase 需要 .json?auth= 格式。
$restful = new RESTful('https://<yourcompany>.com/<path>/<to>/<resource>', '<token>');
$restful->setPathConfiguration('.json?auth=');
$restful->post($path, $data);
头部身份验证
要设置头部请求中的身份验证
$restful->setHeaderProperty('<name_of_property>');
完整的头部属性将是
'<name_of_property>: <token>'
库方法列表
delete($path)
get($path)
getHeaderLocation()
getHeaderResponseCode()
getResponseBody()
patch($path, $data)
post($path, $data)
put($path, $data)
setBaseURI($baseURI)
setContentType($contentType)
setHeaderProperty($headerProperty)
setPathConfiguration($pathConfiguration)
setTimeOut($seconds)
setToken($token)
单元测试
所有的单元测试都位于 "/tests" 目录中。
可以通过运行以下命令执行 RESTful 测试
所有测试
$ phpunit
测试组
$ phpunit --group <groupName>
单个测试
$ phpunit tests/unit/<file_name.php>
我从 firebase-php 库 (https://github.com/ktamas77/firebase-php) 开始。Tamas 的代码非常棒!我帮助他编写了测试和测试存根。我联系他分叉和抽象代码,但他从未回复。
-- Firebase PHP 类 & 客户端库 --
https://github.com/ktamas77/firebase-php @作者 Tamas Kalman ktamas77@gmail.com