Giter Site home page Giter Site logo

apiclient's Introduction

通用 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: 配置参数

参数说明:

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

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

rawResponse: 获取原始响应数据

$raw = $api->rawResponse();

apiclient's People

Contributors

zhouyl avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.