- PHP >= 5.4
- cURL library enabled
{
"require": {
"sylouuu/php-curl": "0.7.*"
}
}require_once './vendor/autoload.php';// Namespace shortcut
use sylouuu\Curl\Method as Curl;
// Template
$request = new Curl\<METHOD_NAME>( string $url [, array $options ] );Methods are:
Get()Head()Options()Post()Put()Patch()Delete()
[
'data' => [ // Data to send, available for `Post`, `Put` and `Patch`
'foo' => 'bar'
],
'headers' => [ // Additional headers (optional)
'Authorization: foobar'
],
'ssl' => '/cacert.pem', // Use it for SSL (optional)
'autoclose' => true // Is the request must be automatically closed (optional)
]// Send a request
$request->send();
// HTTP status code
$request->getStatus();
// HTTP header
$request->getHeader();
// HTTP body response
$request->getResponse();
// Used cURL options
$request->getCurlOptions();
// Set a cURL option
$request->setCurlOption(CURLOPT_SOMETHING, $value);
// Manually close the handle (necessary when `autoclose => false` is used)
$request->close();Basic:
// Namespace shortcut
use sylouuu\Curl\Method as Curl;
// Standard GET request
$request = new Curl\Get('http://domain.com');
// Send this request
$request->send();
echo $request->getResponse(); // body response
echo $request->getStatus(); // HTTP status codeManual:
// Namespace shortcut
use sylouuu\Curl\Method as Curl;
// Set `autoclose` option to `false`
$request = new Curl\Get('http://domain.com', [
'autoclose' => false
]);
// Send this request
$request->send();
// Now you can retrieve a cURL info as the handle is still open
$request->getCurlInfo(CURLINFO_SOMETHING);
echo $request->getResponse();
// Manually close the handle
$request->close();On project directory:
composer installto retrievephpunitphpunitto run tests
2014-10-23 - 0.7.1
- fixed
Post()which didn't send data in some cases
2014-08-01 - 0.7.0 (BC break)
- moved from psr-0 autoload to psr-4
- added
Methoddirectory, then methods are now in\sylouuu\Curl\Method\
2014-05-30 - 0.6.1
- removed exception when
dataoption is not specified forPostPutandPatch
2014-05-22 - 0.6.0 (BC break)
- moved
urloption to the first constructor parameter
2014-05-20 - 0.5.0 (BC break)
- renamed repository from
php-rest-clienttophp-curl - refactored all code
- added
autocloseoption - added the way to get/set cURL options
- added the way to get cURL info
- sources are now psr-2 compliant
2014-05-13 - 0.4.0 (BC break)
- renamed
RESTClient.class.phptoRESTClient.php - moved
RESTClient.phpto/src - moved
RESTClientTest.phpto/tests - added
HEAD,OPTIONSandPATCHsupport - added
getHeadermethod - renamed
getJSONtogetResponse - removed JSON validation
- added
sylouuunamespace - removed
gulp
2014-05-09 - 0.3.0
- added
ssloption
2014-04-06 - 0.2.1
- added exception if invalid JSON format returned
2014-04-04 - 0.2.0
- new way to retrieve result
- added HTTP status code
2014-04-01 - 0.1.0
- refactored class
- removed constructor parameter
- added unit tests
2014-03-24 - 0.0.2
- added
$api_urlas a constructor parameter
2014-02-05 - 0.0.1
- Initial release