2017 © Pedro Peláez
 

library json-client

JSON Client that extends Guzzle and allows to easily send and receive json data.

image

duffleman/json-client

JSON Client that extends Guzzle and allows to easily send and receive json data.

  • Thursday, March 30, 2017
  • by Duffleman
  • Repository
  • 2 Watchers
  • 1 Stars
  • 708 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 20 Versions
  • 9 % Grown

The README.md

json-client

JSON Client for PHP, (*1)

About

I always use JSON API's but Guzzle alone requires a lot of setup for making it only handle JSON bodies and responses. So I built this., (*2)

Basic Usage

<?php

require 'vendor/autoload.php';

use Duffleman\JSONClient\JSONClient;

$client = new JSONClient('http://jsonplaceholder.typicode.com/');

try {
    $response = $client->request('GET', 'users');

    foreach ($response as $user) {
        echo $user->name."\n";
        echo $user->address->geo->lat."\n";
        echo $user->company->name."\n";
        echo "\n";
    }
} catch (Exception $error) {
    dump($error);
}

Post request

<?php

require 'vendor/autoload.php';

use Duffleman\JSONClient\JSONClient;

// important trailing slash
$client = new JSONClient('https://api.avocado.cuv-nonprod.app/1/service-staff/');

try {
    $response = $client->request('POST', '1/latest/list_staff_public');

    foreach ($response as $staff) {
        echo $staff->about->name.' ('.$staff->about->role.')';
        echo "\n";
    }
} catch (Exception $error) {
    dump($error);
}

Using Helpers

Currently, this library includes 2 helper functions it uses, but are public for you to use too. They exist in the Duffleman\JSONClient namespace., (*3)

Example

<?php

use function Duffleman\JSONClient\encode;

require 'vendor/autoload.php';

// Do not forget the use statement!
// But afterwards, we can use it as a normal function :)

$my_data = [
    'name' => 'James',
    'age' => 21,
    'admin' => true,
];

$json = encode($my_data);

echo $json;

The Versions

30/03 2017

dev-master

9999999-dev

JSON Client that extends Guzzle and allows to easily send and receive json data.

  Sources   Download

MIT

The Requires

 

The Development Requires

by George Miller

25/02 2017

dev-develop

dev-develop

JSON Client that extends Guzzle and allows to easily send and receive json data.

  Sources   Download

MIT

The Requires

 

The Development Requires

by George Miller

25/02 2017

1.0.3

1.0.3.0

JSON Client that extends Guzzle and allows to easily send and receive json data.

  Sources   Download

MIT

The Requires

 

The Development Requires

by George Miller

25/02 2017

1.0.2

1.0.2.0

JSON Client that extends Guzzle and allows to easily send and receive json data.

  Sources   Download

MIT

The Requires

 

The Development Requires

by George Miller

21/06 2016

1.0.1

1.0.1.0

JSON Client that extends Guzzle and allows to easily send and receive json data.

  Sources   Download

MIT

The Requires

 

The Development Requires

by George Miller

21/06 2016

1.0.0

1.0.0.0

JSON Client that extends Guzzle and allows to easily send and receive json data.

  Sources   Download

MIT

The Requires

 

The Development Requires

by George Miller

01/06 2016

0.1.1

0.1.1.0

JSON Client that extends Guzzle and allows for easy send an receive of json data.

  Sources   Download

MIT

The Requires

 

The Development Requires

by George Miller

29/05 2016

0.1.0

0.1.0.0

JSON Client that extends Guzzle and allows for easy send an receive of json data.

  Sources   Download

MIT

The Requires

 

The Development Requires

by George Miller

18/05 2016

0.0.12

0.0.12.0

JSON Client that extends Guzzle and allows for easy send an receive of json data.

  Sources   Download

MIT

The Requires

 

by George Miller

14/05 2016

0.0.11

0.0.11.0

JSON Client that extends Guzzle and allows for easy send an receive of json data.

  Sources   Download

MIT

The Requires

 

by George Miller

14/05 2016

0.0.10

0.0.10.0

JSON Client that extends Guzzle and allows for easy send an receive of json data.

  Sources   Download

MIT

The Requires

 

by George Miller

11/05 2016

0.0.9

0.0.9.0

JSON Client that extends Guzzle and allows for easy send an receive of json data.

  Sources   Download

MIT

The Requires

 

by George Miller

11/05 2016

0.0.8

0.0.8.0

JSON Client that extends Guzzle and allows for easy send an receive of json data.

  Sources   Download

MIT

The Requires

 

by George Miller

11/05 2016

0.0.7

0.0.7.0

JSON Client that extends Guzzle and allows for easy send an receive of json data.

  Sources   Download

MIT

The Requires

 

The Development Requires

by George Miller

11/05 2016

0.0.6

0.0.6.0

JSON Client that extends Guzzle and allows for easy send an receive of json data.

  Sources   Download

MIT

The Requires

 

The Development Requires

by George Miller

11/05 2016

0.0.5

0.0.5.0

JSON Client that extends Guzzle and allows for easy send an receive of json data.

  Sources   Download

MIT

The Requires

 

The Development Requires

by George Miller

11/05 2016

0.0.4

0.0.4.0

JSON Client that extends Guzzle and allows for easy send an receive of json data.

  Sources   Download

MIT

The Requires

 

The Development Requires

by George Miller

11/05 2016

0.0.3

0.0.3.0

JSON Client that extends Guzzle and allows for easy send an receive of json data.

  Sources   Download

MIT

The Requires

 

The Development Requires

by George Miller

11/05 2016

0.0.2

0.0.2.0

JSON Client that extends Guzzle and allows for easy send an receive of json data.

  Sources   Download

MIT

The Requires

 

The Development Requires

by George Miller

10/05 2016

0.0.1

0.0.1.0

JSON Client that extends Guzzle and allows for easy send an receive of json data.

  Sources   Download

MIT

The Requires

 

The Development Requires

by George Miller