Coder Social home page Coder Social logo

mikecbrant / php-rest-client Goto Github PK

View Code? Open in Web Editor NEW
11.0 1.0 2.0 97 KB

A PHP cURL REST client class with has multi_exec support

License: MIT License

PHP 99.68% Shell 0.32%
php php7 rest rest-client phpunit curl curl-multi curl-library php5

php-rest-client's Introduction

Build Status Code Climate Test Coverage

php-rest-client

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

  • 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.

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

Requires:

  • PHP 5.6+
  • PHP cURL extension
  • PHPUnit 5.7+ (for unit tests only)

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

Full library documentation

Travis CI build status

Code Climate code coverage and health information

Packagist page

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

php-rest-client's People

Contributors

liorll avatar mikecbrant avatar sos-productions avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

php-rest-client's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.