yaroslawww/laravel-api-response

This package is abandoned and no longer maintained. The author suggests using the laravel/framework package instead.

Submitting structured responses is easy

2.0.1 2020-11-05 15:40 UTC

This package is auto-updated.

Last update: 2020-11-07 17:45:54 UTC


README

Software License Build Status StyleCI Quality Score Code Coverage PHP Version Packagist Version

Installation

You can install the package via composer:

composer require yaroslawww/laravel-api-response
# .env
API_VERSION="1.1"

You can publish the config file with:

php artisan vendor:publish --provider="Gcsc\LaravelApiResponse\ApiResponseProvider" --tag="config"

Usage

Route::get('/', function () {
    return ApiResponse::ok();
});
Route::get('/', function (Request $request) {
    $note = Note::create(['text' => $request->text]);
    return ApiResponse::created($note, 'New note created!');
});

verssion >= 2.0 support laravel Resource object

Route::get('/api/profile', function (Request $request) {
    return ApiResponse::created(new \App\Http\Resources\User\Profile($request->user()));
});
>>> (string)ApiResponse::setMessage('Page expired')->send([], 419);
=> """
   HTTP/1.0 419 unknown status\r\n
   Cache-Control: no-cache, private\r\n
   Content-Type:  application/json\r\n
   Date:          Wed, 29 Jan 2020 14:06:07 GMT\r\n
   \r\n
   {"data":[],"meta":{"version":"1.1","environment":"development"},"message":"Page expired"}
   """

Testing

composer test

Security

If you discover any security related issues, please email yaroslav.georgitsa@gmail.com instead of using the issue tracker.

License

The MIT License (MIT). Please see License File for more information.