2017 © Pedro Peláez
 

library prest

A REST client for PHP based on Pest.

image

zangue/prest

A REST client for PHP based on Pest.

  • Monday, May 2, 2016
  • by zangue
  • Repository
  • 1 Watchers
  • 0 Stars
  • 5 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 3 Versions
  • 25 % Grown

The README.md

Prest

Prest is a PHP REST client library based on Pest. In a nutshell Prest is a wrapper around Pest that let you write RESTful client in a more elegant way (imho)., (*1)

Installation

Via composer cli:, (*2)

composer require zangue/prest

or in your composer.json file:, (*3)

{
    "require": {
        "zangue/prest": "1.0.0"
    }
}

Basic Usage


$factory = new PrestFactory('http://example.com'); $rest = $factory->create() ->url('/resource') ->withHeader('Authorization', 'Basic ' . OAUTH_BASIC)) ->contentType('application/x-www-form-urlencoded') ->accept('application/json') ->data('data1', value1) ->data('data2', value2) ->viaPost() ->execute(); if ($rest->succeed()) { var_dump($rest->getResponseBody()); } else { ... } $rest->reset() ->url('/delete/13') ->viaDelete() ->execute(); if ($rest->failed()) { $e = $rest->getException(); var_dump($e->getMessage()); } $rest2 = $factory->create('http://base-url.com') ->url('/uri') ->viaGet() ->execute(); ...

Just as with Pest one can use the createJSON() and createXML() factory methods to create JSON and XML-centric version of Prest., (*4)

API

Prest url (string $value)

Set the resource URL., (*5)

string getUrl ()

Returns the resource URL, empty string if not set., (*6)

Prest withHeader (string $key, string $value)

Adds a header., (*7)

array getHeaders ()

Returns the request headers, empty array if no headers were set., (*8)

Prest contentType (string $value)

Shortcut: adds Content-Type header., (*9)

Prest data (mixed $key, mixed $value)

Adds request data, (*10)

Prest arrayData (array $data)

Use this method to pass a prepared array of data. Argument has to be an array else nothing will happened!, (*11)

array getData ()

Returns the request data, empty array if no data were set., (*12)

Prest withCookie (string $name, string $value)

Add a cookie., (*13)

array getCookies ()

Returns array of cookies or empty array if no cookies were added to the request., (*14)

Prest withAuth (string $user, string $pass, string $auth = 'basic')

Setup authentication. $auth can basic (default) or disgest., (*15)

Prest withProxy (string $host, int $port, [string $user, string $pass])

Setup proxy., (*16)

Prest function curlOpts (string $option, mixed $value)

Set cURL option., (*17)

boolean succeed ()
boolean failed()

Tells if the request was successful/failed., (*18)

int getStatus ()

Get last response status code, (*19)

Exception getException ()

Return the raised exception in case of failure., (*20)

mixed getResponseBody ()

Returns the last response body on success. This method will return an associative array or a SimpleXMLElement if the Prest object was created using createJSON or createXML factory method respectively., (*21)

boolean responseHasHeader (string $header)

Checks if last response has a specific header., (*22)

string getResponseHeader (string $header)

Returns the last response header (case insensitive) or NULL if not present., (*23)

Prest viaGet ()
Prest viaPost ()
Prest viaPut ()
Prest viaPatch ()
Prest viaHead ()
Prest viaDelete ()

Use HTTP GET/POST/PUT/PATCH/HEAD/DELETE method., (*24)

Prest execute ()

Executes the request., (*25)

The Versions

02/05 2016

dev-master

9999999-dev https://github.com/zangue/prest

A REST client for PHP based on Pest.

  Sources   Download

MIT

The Requires

 

by Armand Zangue

api php rest client prest pest

01/05 2016

dev-develop

dev-develop https://github.com/zangue/prest

A REST client for PHP based on Pest.

  Sources   Download

MIT

The Requires

 

by Armand Zangue

api php rest client prest pest

28/04 2016

v1.0.0

1.0.0.0 https://github.com/zangue/prest

A REST client for PHP based on Pest.

  Sources   Download

MIT

The Requires

 

by Armand Zangue

api php rest client prest pest