Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/rap2hpoutre/jacky
:cow2: HTTP JSON API Client for Laravel & Lumen
https://github.com/rap2hpoutre/jacky
api-client guzzle json laravel lumen php
Last synced: 3 months ago
JSON representation
:cow2: HTTP JSON API Client for Laravel & Lumen
- Host: GitHub
- URL: https://github.com/rap2hpoutre/jacky
- Owner: rap2hpoutre
- License: mit
- Created: 2015-10-17T13:45:45.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2016-02-08T15:02:49.000Z (almost 9 years ago)
- Last Synced: 2024-10-14T10:46:26.468Z (4 months ago)
- Topics: api-client, guzzle, json, laravel, lumen, php
- Language: PHP
- Homepage: http://twitter.com/rap2h
- Size: 28.3 KB
- Stars: 17
- Watchers: 2
- Forks: 6
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Jacky
[![Packagist](https://img.shields.io/packagist/v/rap2hpoutre/jacky.svg)]()
[![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE)
[![Build Status](https://img.shields.io/scrutinizer/build/g/rap2hpoutre/jacky.svg?style=flat-square)](https://travis-ci.org/rap2hpoutre/jacky)
[![Quality Score](https://img.shields.io/scrutinizer/g/rap2hpoutre/jacky.svg?style=flat-square)](https://scrutinizer-ci.com/g/jacky/nestor)
[![SensioLabsInsight](https://insight.sensiolabs.com/projects/27adcd2f-20de-4555-8753-3ece7ee24495/mini.png)](https://insight.sensiolabs.com/projects/27adcd2f-20de-4555-8753-3ece7ee24495)JSON API Client for Laravel and Lumen. It's basically just a [Guzzle](https://github.com/guzzle/guzzle) wrapper for JSON, because Guzzle [does not care](http://stackoverflow.com/questions/30530172/guzzle-6-no-more-json-method-for-responses) about JSON anymore. And you can configure your endpoints once and for all in a [configuration file](https://github.com/rap2hpoutre/jacky/blob/master/src/config.php), could be useful if you work with different services.
## InstallInstall via composer
```
composer require rap2hpoutre/jacky
```
Add Service Provider to `config/app.php` in `providers` section
```php
Rap2hpoutre\Jacky\ServiceProvider::class,
```Then add the facade in `aliases` section (optional)
```php
'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`:
```json
{
"data": [{
"name": "John Doe",
"email": "[email protected]"
}]
}
```You may get the user like this:
```php
$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:
```json
{
"errors": [{
"status": "404",
"title": "User not found :/"
}]
}
```You may display error title like this:
```php
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](https://github.com/rap2hpoutre/jacky/blob/master/src/config.php)