faridibin / laravel-api-response

Easy way to implement API formatted json responses.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Laravel Json Response

An Ethereal Package

Easy way to implement API formatted json responses.

Format:

{
    "data": {...},
    "errors": [],
    "success": true,
    "status_code": 200,
    "token": null
}

Setup

Install:

composer require Faridibin/laravel-json-response

Add the service provider to your app config:

\Faridibin\LaravelJsonResponse\Providers\LaravelJsonResponseProvider::class,

Add the middleware to your app\Http\Kernel.php

Either:

// Formats all responses in json. Catches errors listed in config and JsonResponseErrorExceptions
Faridibin\LaravelJsonResponse\Middleware\OutputJsonResponse, 

// Extends the OutputJsonResponse to catch all errors, to keep the JSON output
Faridibin\LaravelJsonResponse\Middleware\CatchAllExceptions, 

Config

Publish the config by using the command:

php artisan vendor:publish

About

Easy way to implement API formatted json responses.


Languages

Language:PHP 100.0%