jaenmedina/php-rest-client

PHP REST 客户端。

0.3.0 2017-07-06 03:15 UTC

This package is not auto-updated.

Last update: 2024-09-28 17:17:51 UTC


README

Build Status Codacy Badge Code Climate

PHP REST 客户端。

版本

0.1.0

使用 composer 安装

在您的 composer.json 中添加包依赖项 softiciel/php-rest-client

{
    "require": {
        "softiciel/php-rest-client": "0.3.0"
    }
}

如何使用?

只需实例化您要执行的方法。支持 GET、POST、PUT、HEAD、DELETE 和 OPTIONS 方法。

对于 GET 方法

$url = 'http://www.example.com';
$getMethod = new Get($url);
$result = $getMethod->execute();
print_r($result); // Will print the array with keys 'status', 'time', 'header', 'body' and 'error'.

对于 POST 方法

$url = 'https://httpbin.org/post';
$postMethod = new Post($url);
$postMethod->setParameter('text', 'Read these tips to improve');
$result = $postMethod->execute();
print_r($result); // Will print the array with keys 'status', 'time', 'header', 'body' and 'error'.

对于 PUT 方法

$url = 'https://httpbin.org/put';
$putMethod = new Put($url);
$data = 'Test data';
$result = $putMethod->execute($data);
print_r($result); // Will print the array with keys 'status', 'time', 'header', 'body' and 'error'.

对于 HEAD 方法

$url = 'http://www.example.com';
$headMethod = new Head($url);
$result = $headMethod->execute();
print_r($result); // Will print the array with keys 'status', 'time', 'header', and 'error'.

对于 OPTIONS 方法

$url = 'http://www.example.com';
$optionsMethod = new Options($url);
$result = $optionsMethod->execute();
print_r($result); // Will print the array with keys 'status', 'time', 'header', 'body' and 'error'

对于 DELETE 方法

$url = 'https://httpbin.org/DELETE';
$deleteMethod = new Delete($url);
$result = $deleteMethod->execute();
print_r($result); // Will print the array with keys 'status', 'time', 'header', 'body' and 'error'

对于自定义方法

$url = 'http://www.example.com';
$customMethod = new CustomMethod($url);
$result = $customMethod->execute('EXECUTE');
print_r($result); // Will print the array with keys 'status', 'time', 'header', 'body' and 'error'

您还可以使用 RestClient 类

$result = RestClient::execute([
    'method' => 'get',
    'url' => 'www.example.org'
]);
print_r($result); // Will print the array with keys 'status', 'time', 'header', 'body' and 'error'

许可证

MIT