2017 © Pedro Peláez
 

library lib-http-client

HTTP client library of the Ride framework

image

ride/lib-http-client

HTTP client library of the Ride framework

  • Wednesday, July 26, 2017
  • by ride-user
  • Repository
  • 7 Watchers
  • 0 Stars
  • 3,319 Installations
  • PHP
  • 6 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 14 Versions
  • 2 % Grown

The README.md

Ride: HTTP Client Library

HTTP client library of the PHP Ride framework., (*1)

What's In This Library

Client

The Client interface lets you implement an HTTP client., (*2)

Out of the box, the cURL implementation is provided through the CurlClient class, (*3)

Request

The Request class adds authentication and other client options to the default HTTP request., (*4)

Code Sample

Check the following code sample to see how this library should be used:, (*5)

<?php

use ride\library\http\client\CurlClient;
use ride\library\http\client\Client;
use ride\library\http\HttpFactory;
use ride\library\log\Log;

function createHttpClient(HttpFactory $httpFactory, Log $log) {
    $client = new CurlClient($httpFactory);

    // optionally set a log, to follow the communication of the client
    $client->setLog($log);

    // set some basic options
    $client->setTimeout(3);
    $client->setFollowLocation(true);
    $client->setUserAgent('My-UserAgent');    

    // use authentication for the requests
    $client->setAuthenticationMethod('basic');
    $client->setAuthenticationMethod('digest');
    $client->setUsername('my-username');
    $client->setPassword('my-password');

    // use a proxy
    $client->setProxy('http://url.to/some-proxy);

    return $client;
}

function sendRequests(Client $client) {
    // shortcuts for simple requests
    $response = $client->get('http://www.google.com');
    $response = $client->get('http://www.google.com', array('Cache-Control' => 'no-cache'));
    $response = $client->head('http://www.google.com');
    $response = $client->head('http://www.google.com', array('Cache-Control' => 'no-cache'));

    // simple post request
    $response = $client->post('http://www.google.com');
    // with body
    $response = $client->post('http://www.google.com', array('q' => 'search string'));
    // and headers
    $response = $client->post('http://www.google.com', array('q' => 'search string'), array('Accept' => '*/*'));

    // the same for put and delete
    $response = $client->put('http://www.google.com');
    $response = $client->put('http://www.google.com', array('q' => 'search string'));
    $response = $client->put('http://www.google.com', array('q' => 'search string'), array('Accept' => '*/*'));
    $response = $client->delete('http://www.google.com', array('q' => 'search string'), array('Accept' => '*/*'));

    // you can create your own request and tune it before sending it out
    $request = $client->createRequest('https://www.google.com');
    $request->setFollowLocation($followLocation);
    $request->setAuthenticationMethod('basic');
    $request->setUsername('my-username');
    $request->setPassword('my-password');

    $response = $client->sendRequest($request);

    // handle response
    if ($response->isOk()) {
        $contentType = $response->getHeader('Content-Type');
        $body = $response->getBody();
    } else {
        $statusCode = $response->getStatusCode();
        switch ($statusCode) {
            case 403:
                // forbidden
                break;
            // and more
        }
    }
}

You can check the following related modules of this library:, (*6)

Installation

You can use Composer to install this library., (*7)

composer require ride/lib-http-client

The Versions

26/07 2017

dev-develop

dev-develop

HTTP client library of the Ride framework

  Sources   Download

MIT

The Requires

 

by Joris Vandeweerd

12/10 2016

dev-master

9999999-dev

HTTP client library of the Ride framework

  Sources   Download

MIT

The Requires

 

by Joris Vandeweerd

12/10 2016

1.0.1

1.0.1.0

HTTP client library of the Ride framework

  Sources   Download

MIT

The Requires

 

by Joris Vandeweerd

11/10 2016

1.0.0

1.0.0.0

HTTP client library of the Ride framework

  Sources   Download

MIT

The Requires

 

by Joris Vandeweerd

04/05 2016

0.4.0

0.4.0.0

HTTP client library of the Ride framework

  Sources   Download

MIT

The Requires

 

by Joris Vandeweerd

24/11 2015

0.3.0

0.3.0.0

HTTP client library of the Ride framework

  Sources   Download

MIT

The Requires

 

by Joris Vandeweerd

11/08 2015

0.2.1

0.2.1.0

HTTP client library of the Ride framework

  Sources   Download

MIT

The Requires

 

by Joris Vandeweerd

11/08 2015

0.2.0

0.2.0.0

HTTP client library of the Ride framework

  Sources   Download

MIT

The Requires

 

by Joris Vandeweerd

29/04 2015

0.1.5

0.1.5.0

HTTP client library of the Ride framework

  Sources   Download

MIT

The Requires

 

by Joris Vandeweerd

12/02 2015

0.1.4

0.1.4.0

HTTP client library of the Ride framework

  Sources   Download

MIT

The Requires

 

by Joris Vandeweerd

06/05 2014

0.1.3

0.1.3.0

HTTP client library of the Ride framework

  Sources   Download

MIT

The Requires

 

by Joris Vandeweerd

25/03 2014

0.1.2

0.1.2.0

HTTP client library of the Ride framework

  Sources   Download

MIT

The Requires

 

by Joris Vandeweerd

18/02 2014

0.1.1

0.1.1.0

HTTP client library of the Pallo framework

  Sources   Download

MIT

The Requires

 

by Joris Vandeweerd

26/12 2013

0.1.0

0.1.0.0

HTTP client library of the Pallo framework

  Sources   Download

MIT

The Requires

 

by Joris Vandeweerd