staskjs / simple-api
此包的最新版本(1.3.0)没有提供许可信息。
用于为PHP创建简单API封装的库
1.3.0
2018-03-13 13:26 UTC
Requires
- guzzlehttp/guzzle: ^6.2
This package is not auto-updated.
Last update: 2024-09-29 02:08:28 UTC
README
安装
composer require staskjs/simple-api
使用
为您的API封装创建类。
use Staskjs\SimpleApi\SimpleJsonApi;
class GithubApi extends SimpleJsonApi {
// Headers for each request
protected $headers = [
'Authorization' => 'token TOKEN',
];
// Specify default query params for each request (for example this can be api version or api token)
protected $default_query = [
];
public function getUsers() {
return $this->request('GET', 'users');
}
}
// ...
$api = new GithubApi('https://api.github.com');
$success = $api->getUsers();
// If http query was successful
if ($success) {
$data = $api->getData();
}
else {
$errors = $api->getErrors();
}