arikin/api_client

基本API客户端

0.1.4 2017-10-10 06:48 UTC

This package is not auto-updated.

Last update: 2024-09-29 05:01:28 UTC


README

使用GuzzleHttp 6的简单PHP API客户端

概述

PHP 7和新的GuzzleHttp 6的RESTful API。这是将旧项目从guzzle版本4转换为最新版本6的转换 guzzlehttp/guzzle

返回Guzzle的API对象。创建一个理解给定API服务器API命令的类。然后使用此API对象执行get、post等操作。

安装

在项目中要求它

php composer.phar require arikin/api_client

用法

需要类,并用API服务器的基本URL和凭据初始化它。

require_once __DIR__ . '/vendor/autoload.php';

use Arikin\ApiClient;

$client = new ApiClient(array(
    'url' => 'http://api.server.net',
    'user' => 'api_username',
    'pass' => 'secret_password'
 ));

$resp_obj = $client->api->get('/user/list');
$code = $resp_obj->getStatusCode();
$reason = $resp_obj->getReasonPhrase();

$body_string = (string) $resp_obj->getBody();
$data_array = json_decode($body_string,TRUE);