Looking to hire Laravel developers? Try LaraJobs

laravel-api-response maintained by yaroslawww

Description
Submitting structured responses is easy
Last update
2020/11/05 16:40 (dev-master)
License
Downloads
78

Comments
comments powered by Disqus

Submitting structured responses is easy

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.