softiciel / php-rest-client
A PHP REST Client.
0.3.0
2017-07-06 03:15 UTC
Requires
- php: >=5.4
Requires (Dev)
- guzzlehttp/guzzle: ~5.0
- phpunit/phpunit: 3.7.*
This package is not auto-updated.
Last update: 2025-03-29 02:20:29 UTC
README
A PHP REST Client.
Version
0.1.0
Install with composer
Add the package dependency softiciel/php-rest-client in your composer.json
{ "require": { "softiciel/php-rest-client": "0.3.0" } }
How to use?
Just instantiate the method you want to execute. There is support for GET, POST, PUT HEAD, DELETE and OPTIONS methods.
For GET method:
$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'.
For POST method:
$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'.
For PUT method:
$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'.
For HEAD method:
$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'.
For OPTIONS method:
$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'
For DELETE method:
$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'
For custom method:
$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'
You can also use the RestClient class:
$result = RestClient::execute([ 'method' => 'get', 'url' => 'www.example.org' ]); print_r($result); // Will print the array with keys 'status', 'time', 'header', 'body' and 'error'
License
MIT