Code Monkey home page Code Monkey logo

jacky's Introduction

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": "[email protected]"
  }]
}

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

jacky's People

Contributors

rap2hpoutre avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

jacky's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.