2017 © Pedro Peláez
 

library httpeep

PHP HTTP client for API endpoint/resource requests

image

mykehowells/httpeep

PHP HTTP client for API endpoint/resource requests

  • Monday, March 14, 2016
  • by mykemeynell
  • Repository
  • 1 Watchers
  • 0 Stars
  • 29 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 4 Versions
  • 0 % Grown

The README.md

HttPeep

PHP HTTP client for API endpoint/resource requests, (*1)

Setup

Composer

If you use composer, enter the following command into terminal:, (*2)

composer require mykehowells/httpeep, (*3)

Then add require 'vendor/autoloader.php' to your PHP project., (*4)

Non-Composer

To start using HttPeep, clone this repo into your project; Using SPL autoloader, enter the following code into your project to load the required files., (*5)

set_include_path( CLASSES_DIR );
spl_autoload_extensions('.class.php');
spl_autoload_register();

This will include the files as they are called within your project and within he HttPeep files., (*6)

Usage

A simple use case of HttPeep, is below;, (*7)

$client = new \HttPeep\Client( 'https://api.example.com' );

$response = $client->post( "/user/auth", [
     'token' => $_SESSION['api']['token'],
     'username' => $_POST['username'],
     'password' => md5( $_POST['password'] )
] );

var_export( $response );

You can also use the \HttPeep\Client->json() method to return JSON taken from the body., (*8)

$client = new \HttPeep\Client( 'https://api.example.com' );

$response = $client->post( "/user/auth", [
     'token' => $_SESSION['api']['token'],
     'username' => $_POST['username'],
     'password' => md5( $_POST['password'] )
] )->json();

var_export( $response );

Methods

Methods available from HttPeep are:, (*9)

  • GET
  • POST
  • DELETE
  • PUT

Client Config

When instantiating \HttPeep\Client(), you can pass an array of config variables for cURL; for example:, (*10)

$client = new \HttPeep\Client( 'https://api.example.com', [
    'curl' => [
        'followlocation' => true, // CURLOPT_FOLLOWLOCATION - follow any Location: header sent as part of the HTTP header
        'maxredirs' => 10 // CURLOPT_MAXREDIRS - Maximum number of HTTP redirections to follow
    ]
] );

Default CURLOPTS that are set within the Client are:, (*11)

Option Value
CURLOPT_RETURNTRANSFER true
CURLOPT_SSL_VERIFYPEER false
CURLOPT_SSL_VERIFYHOST false
CURLOPT_VERBOSE false

The Versions

14/03 2016

dev-master

9999999-dev https://github.com/mykehowells/HttPeep

PHP HTTP client for API endpoint/resource requests

  Sources   Download

GPL

The Requires

  • php >=5.4.0

 

api php rest http request client response httpeep

10/03 2016

1.0.2

1.0.2.0 https://github.com/mykehowells/HttPeep

PHP HTTP client for API endpoint/resource requests

  Sources   Download

GPL

The Requires

  • php >=5.4.0

 

api php rest http request client response httpeep

16/01 2016

1.0.1

1.0.1.0 https://github.com/mykehowells/HttPeep

PHP HTTP client for API endpoint/resource requests

  Sources   Download

GPL

The Requires

  • php >=5.4.0

 

api php rest http request client response httpeep

12/01 2016

1.0.0

1.0.0.0 https://github.com/mykehowells/HttPeep

PHP HTTP client for API endpoint/resource requests

  Sources   Download

GPL

The Requires

  • php >=5.4.0

 

api php rest http request client response httpeep