A PHP cURL REST client class with has multi_exec support
MIT License
This library provides classes implementing basic REST clients based on PHP's cURL extension. Two client classes are made available:
Additionally, this library provides classes which wrap curl responses within object oriented interface:
These classes support:
Requires:
This library is developed against PHP 7.1 and tested via Travis CI against:
Code Climate code coverage and health information
Usage example:
<?php
use MikeBrant\RestClientLib;
/**
* Single request using RestClient
*/
$restClient = new RestClient();
$restClient->setRemoteHost('foo.bar.com')
->setUriBase('/some_service/')
->setUseSsl(true)
->setUseSslTestMode(false)
->setBasicAuthCredentials('username', 'password')
->setHeaders(array('Accept' => 'application/json'));
// make requests against service
$response = $restClient->get('resource');
$response = $restClient->post('resource', $data);
$response = $restClient->put('resource', $data);
$response = $restClient->delete('resource');
$response = $restClient->head('resource');
/**
* Multiple parallel requests using RestMultiClient
*/
$restMultiClient = new RestMultiClient();
$restMultiClient->setRemoteHost('foo.bar.com')
->setUriBase('/some_service/')
->setUseSsl(true)
->setUseSslTestMode(false)
->setBasicAuthCredentials('username', 'password')
->setHeaders(array('Accept' => 'application/json'));
// make requests against service
$responses = $restMultiClient->get(['resource1', 'resource2', ...]);
$responses = $restMultiClient->post(['resource1', 'resource2', ...], [$data1, $data2, ...]);
$responses = $restMultiClient->put(['resource1', 'resource2', ...], [$data1, $data2, ...]);
$responses = $restMultiClient->delete(['resource1', 'resource2', ...]);
$responses = $restMultiClient->head(['resource1', 'resource2', ...]);