2017 © Pedro Peláez
 

library apiclient

Common API Client

image

zhouyl/apiclient

Common API Client

  • Saturday, July 26, 2014
  • by zhouyl
  • Repository
  • 1 Watchers
  • 0 Stars
  • 6 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

通用 API 客户端

Composer 加载说明

{
    "require": {
        "zhouyl/apiclient": "dev-master"
    }
}

使用说明

示例代码

$api = new \ZhouYL\Api\Client([
    'gateway' => 'http://127.0.0.1',
    'headers' => array(
        'Host: api.fanqie88.com',
    ),
    'port' => 9433,
    'timeout' => 10,
]);

config: 配置参数

参数说明:, (*1)

gateway:    URL请求网关
port:       端口,默认自动识别
headers:    CURL请求附加头信息
timeout:    超时时间,默认不限制

request: 执行请求

$json = $api->request('Api/xxx', array('key' => 'xxx', 'uid' => 12345), 'POST');

get: GET 请求

$json = $api->request('Api/xxx');
// or
$json = $api->get('Api/xxx');

post: POST 请求

$data = array(
    'key' => 'xxx',
    'uid' => 12345,
);

$json = $api->request('Api/xxx', $data, 'POST');
// or
$json = $api->post('Api/xxx', $data);

response: 获取响应数据

Client 将尝试将响应数据转换进行 json_decode 转换,如果失败则返回 false, (*2)

$api->request('Api/xxx');
$json = $api->response();

rawResponse: 获取原始响应数据

$raw = $api->rawResponse();

The Versions

26/07 2014

dev-master

9999999-dev

Common API Client

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

by Avatar zhouyl