Opinionated REST JSON HTTP API client for laravel
4,206
17
2
Package Data
Maintainer Username: rap2hpoutre
Maintainer Contact: raphaelht@gmail.com (rap2hpoutre)
Package Create Date: 2015-10-17
Package Last Update: 2016-02-08
Home Page: http://twitter.com/rap2h
Language: PHP
License: MIT
Last Refreshed: 2024-04-18 15:14:27
Package Statistics
Total Downloads: 4,206
Monthly Downloads: 1
Daily Downloads: 0
Total Stars: 17
Total Watchers: 2
Total Forks: 6
Total Open Issues: 3

Jacky

Packagist Software License Build Status Quality Score SensioLabsInsight

JSON API Client for Laravel and Lumen. It's basically just a Guzzle wrapper for JSON, because Guzzle does not care about JSON anymore. And you can configure your endpoints once and for all in a configuration file, could be useful if you work with different services.

Install

Install via composer

composer require rap2hpoutre/jacky

Add Service Provider to config/app.php in providers section

Rap2hpoutre\Jacky\ServiceProvider::class,

Then add the facade in aliases section (optional)

'Jacky' => Rap2hpoutre\Jacky\Facade::class,

Publish configuration

php artisan vendor:publish

Usage

Simple example

Let's say foo API returns this on GET /users/1:

{
  "data": [{
    "name": "John Doe",
    "email": "john@example.com"
  }]
}

You may get the user like this:

$user_name = Jacky::get('foo', '/users/1')->data->first()->name;

Not found example

Let's say foo API returns this on GET /users/2 not found:

{
  "errors": [{
    "status": "404",
    "title":  "User not found :/"
  }]
}

You may display error title like this:

use Rap2hpoutre\Jacky\Exception\Http404Exception;

try {
    $user = Jacky::get('foo', '/users/1');
} catch (Http404Exception $e) {
    echo $e->errors->first()->title;
}

Configuration

You can learn more about configuration here