2017 © Pedro Peláez
 

library rest-client

Simple PHP Rest Client

image

sc0/rest-client

Simple PHP Rest Client

  • Sunday, July 30, 2017
  • by sc0rp10
  • Repository
  • 1 Watchers
  • 2 Stars
  • 7,144 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 2 Forks
  • 0 Open issues
  • 6 Versions
  • 2 % Grown

The README.md

PHP REST client

Build Status, (*1)

SensioLabsInsight, (*2)

This is simple and extendable REST client., (*3)

Basic usage

use Sc\RestClient\Client\Client;
use Sc\RestClient\ResponseParser\JsonResponseParser;

$client = new Client('https://api.foo.bar', new JsonResponseParser());

$resource = 'zombies';

// retrieve all objects (will produce GET /zombies/)
$client->getAll($resource);

// create a new resource (will produce POST /zombies/ with following data)
$created = $client->create($resource, [
    'name' => 'Shaun',
    'age' => 29,
]);
// 'create' API should return data or 'Location' header with created resource URI

$id = $created['id'];

// retrieve single object (will produce GET /zombies/123/)
$client->get($resource, $id);

// update full resource (will produce PUT /zombies/123/)
$updated = $client->update($resource, $id, [
    'name' => 'Shaun',
    'age' => 30,
]);

// update resource partially (will produce PATCH /zombies/123/)
$updated = $client->update($resource, $id, [
    'age' => 31,
]);

// delete resource (will produce DELETE /zombies/123/)
$client->delete($resource, $id);

Change response format

use Sc\RestClient\Client\Client;
use Sc\RestClient\ResponseParser\XmlResponseParser;

$client = new Client('https://api.foo.bar', new XmlResponseParser('root_tag_name'));

Implementing own response parser

Just implement Sc\RestClient\ResponseParser\ResponseParserInterface#parseResponse and play with response, (*4)

Custom api authentification

use Sc\RestClient\Client\Client;
use Sc\RestClient\ResponseParser\JsonResponseParser;
use Sc\RestClient\AuthenticationProvider\QueryParameterProvider;
use Sc\RestClient\AuthenticationProvider\HeaderProvider

$client = new Client('https://api.foo.bar', new JsonResponseParser());
$client->useAuthenticator(new QueryParameterProvider('api_key', 'abcd1234'));
// each request will be followed with ?api_key=abcd1234 query string

// or
$client->useAuthenticator(new HeaderProvider('X-Auth-Header', 'abcd1234'));
// each request will be followed with header "X-Auth-Header: abcd1234"

Implementing own authenticator

Sc\RestClient\AuthenticationProvider\AuthenticationProviderInterface#addAuthentificationInfo will play with original request and modify it according with your requirements such as X.509 certificates, (*5)

Request signing

@TODO, (*6)

The Versions

30/07 2017

dev-master

9999999-dev https://github.com/sc0rp10/rest-client

Simple PHP Rest Client

  Sources   Download

MIT

The Requires

 

The Development Requires

rest rest-client

30/07 2017

0.2.0

0.2.0.0 https://github.com/sc0rp10/rest-client

Simple PHP Rest Client

  Sources   Download

MIT

The Requires

 

The Development Requires

rest rest-client

28/09 2016

0.1.3

0.1.3.0 https://github.com/sc0rp10/rest-client

Simple PHP Rest Client

  Sources   Download

MIT

The Requires

 

The Development Requires

rest rest-client

10/08 2016

0.1.2

0.1.2.0 https://github.com/sc0rp10/rest-client

Simple PHP Rest Client

  Sources   Download

MIT

The Requires

 

The Development Requires

rest rest-client

01/08 2016

0.1.1

0.1.1.0 https://github.com/sc0rp10/rest-client

Simple PHP Rest Client

  Sources   Download

MIT

The Requires

 

The Development Requires

rest rest-client

30/12 2015

0.0.1

0.0.1.0 https://github.com/sc0rp10/rest-client

Simple PHP Rest Client

  Sources   Download

MIT

The Requires

 

The Development Requires

rest rest-client