项目作者: rap2hpoutre

项目描述 :
:cow2: HTTP JSON API Client for Laravel & Lumen
高级语言: PHP
项目地址: git://github.com/rap2hpoutre/jacky.git
创建时间: 2015-10-17T13:45:45Z
项目社区:https://github.com/rap2hpoutre/jacky

开源协议:MIT License

下载


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

  1. composer require rap2hpoutre/jacky

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

  1. Rap2hpoutre\Jacky\ServiceProvider::class,

Then add the facade in aliases section (optional)

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

Publish configuration

  1. php artisan vendor:publish

Usage

Simple example

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

  1. {
  2. "data": [{
  3. "name": "John Doe",
  4. "email": "john@example.com"
  5. }]
  6. }

You may get the user like this:

  1. $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:

  1. {
  2. "errors": [{
  3. "status": "404",
  4. "title": "User not found :/"
  5. }]
  6. }

You may display error title like this:

  1. use Rap2hpoutre\Jacky\Exception\Http404Exception;
  2. try {
  3. $user = Jacky::get('foo', '/users/1');
  4. } catch (Http404Exception $e) {
  5. echo $e->errors->first()->title;
  6. }

Configuration

You can learn more about configuration here