jowy / rest-client
PHP 5.3+ Rest Client
v0.1.3
2015-10-11 01:26 UTC
Requires
- php: >=5.3.0
- ext-curl: *
This package is not auto-updated.
Last update: 2024-11-05 03:02:15 UTC
README
Simple cURL PHP Rest Client library for PHP 5.3+
Feature
- Set
HTTP Authentication
- Set
HTTP Header
- Set
Curl Options
GET
,POST
,PUT
,DELETE
Method
Installation
This library can installed through compose
$ php composer.phar require jowy/rest-client:@stable
Usage
<?php include 'vendor/autoload.php'; use RestClient\CurlRestClient; $curl = new CurlRestClient(); $curl->setOptions([CURLOPT_SSL_VERIFYHOST => 0, CURLOPT_SSL_VERIFYPEER => 0]); var_dump($curl->executeQuery('http://www.google.com')); // OR.... $curl = new CurlRestClient('http://www.google.com', array( // Header data 'X-API-KEY: 16251821972', 'OUTPUT: JSON' ), array( // AUTH (curl) 'CURLOPT_HTTPAUTH' => CURLAUTH_DIGEST, 'username' => 'root', 'password' => 'toor' ), array( CURLOPT_SSL_VERIFYHOST => 0, CURLOPT_SSL_VERIFYPEER => 0 ) );
Parameter
url
describe target urlmethod
define HTTP method can beGET
,POST
,PUT
,DELETE
. Default value isDELETE
header
contain array list of headerdata
contain array list of dataauth
contain array list of auth
Example fullset usage
$curl->executeQuery('http://api.somewebsite.com', 'POST', array( 'X-API-KEY: 16251821972', 'OUTPUT: JSON' ), array( 'USERNAME' => 'jowy', 'SERVERID' => '192882' ), array( 'CURLOPT_HTTPAUTH' => CURL_AUTH_DIGEST, 'username' => 'jowy', 'password' => '123456' ) ); // OR USE CONVENIENT METHODS // GET $res = $curl->get('customer/details', array( 'customerId' => 55 )); // POST $res = $curl->post('customer', array( 'name' => 'Ole Nordmann', 'age' => 49, 'address' => 'Stortingsveien 5', 'zip' => '0120', 'city' => 'Oslo' ));