2017 © Pedro Peláez
 

library php-rest-client

PSR-4 PHP Package Boilerplate.

image

mikecbrant/php-rest-client

PSR-4 PHP Package Boilerplate.

  • Thursday, June 8, 2017
  • by mikecbrant
  • Repository
  • 1 Watchers
  • 4 Stars
  • 1,218 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 4 Forks
  • 0 Open issues
  • 1 Versions
  • 5 % Grown

The README.md

Build Status Code Climate Test Coverage, (*1)

php-rest-client

This library provides classes implementing basic REST clients based on PHP's cURL extension. Two client classes are made available:, (*2)

  • RestClient - a class for executing RESTful service calls.
  • RestMultiClient - a class which extends RestClient to provide curl_multi capabilities to allow multiple RESTful calls to be made in parallel.

Additionally, this library provides classes which wrap curl responses within object oriented interface: - CurlHttpResponse - a class which encapsulates an HTTP response received via cURL into a class wrapper. - CurlMultiHttpResponse - a class which represents a collection of CurlHttpRepsonse objects as returned from multiple parallel cURL calls., (*3)

These classes support: - HTTP actions - GET, POST, PUT, DELETE, and HEAD - Basic authentication - SSL, with the ability to toggle SSL certificate validation to help in development/test enviroments, (*4)

Requires: - PHP 5.6+ - PHP cURL extension - PHPUnit 5.7+ (for unit tests only), (*5)

This library is developed against PHP 7.1 and tested via Travis CI against: - PHP 5.6.* - PHP 7.0.* - PHP 7.1.* - PHP Nightly build, (*6)

Full library documentation, (*7)

Travis CI build status, (*8)

Code Climate code coverage and health information, (*9)

Packagist page, (*10)

Usage example:, (*11)

<?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', ...]);

The Versions

08/06 2017

dev-master

9999999-dev

PSR-4 PHP Package Boilerplate.

  Sources   Download

MIT

The Requires

  • ext-curl *
  • php >=5.6

 

The Development Requires

by Mike Brant

curl rest http client http client rest client curl client