PHP code example of zangue / prest

1. Go to this page and download the library: Download zangue/prest library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

zangue / prest example snippets



$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();

...


Prest url (string $value)

string getUrl ()

Prest withHeader (string $key, string $value)

array getHeaders ()

Prest contentType (string $value)

Prest data (mixed $key, mixed $value)

Prest arrayData (array $data)

array getData ()

Prest withCookie (string $name, string $value)

array getCookies ()

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

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

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

boolean succeed ()
boolean failed()

int getStatus ()

Exception getException ()

mixed getResponseBody ()

boolean responseHasHeader (string $header)

string getResponseHeader (string $header)

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

Prest execute ()