laratoolbox/responder is a Laravel package for easily respond to api requests for laravel..
It currently has 4 GitHub stars and 8 downloads on Packagist (latest version v0.1.0).
Install it with composer require laratoolbox/responder.
Discover more Laravel packages by laratoolbox
or browse all Laravel packages to compare alternatives.
Last updated
Easily respond to api requests.
Laravel >= 5.5
You can install the package via composer:
$ composer require laratoolbox/responder
After installation, you can use helper responder function.
return responder()
->addHeader('X-Secret1', 'secret1')
->addHeader('X-Secret2', 'secret2')
->addHeader('X-Secret3', 'secret3')
->setData(\App\Models\User::select('id', 'name')->find(1))
->addExtraData('custom-key', 'custom-value')
->send();
See response below:
HTTP/1.1 200 OK
Content-Type: application/json
X-Secret1: secret1
X-Secret2: secret2
X-Secret3: secret3
{
"code": 0,
"message": null,
"data": {
"id": 1,
"name": "Semih ERDOGAN"
},
"custom-key": "custom-value"
}
Also, you have ResponderException that you can throw it any time required.
throw new \LaraToolbox\Responder\Exceptions\ResponderException(
\LaraToolbox\Responder\ResponseCodes::ERROR,
$customData = [1,2,3]
);
See response below:
HTTP/1.1 200 OK
Content-Type: application/json
{
"code": 120,
"message": "An error occurred",
"data": [
1,
2,
3
]
}
null|mixed $data (if set calls setData method behind the scenes)int $statusCodearray $responseMetaint $responseCodestring $responseMessagemixed $datastring $keymixed $valuestring $keystring|integer|numeric $value// TODO:
Please see CHANGELOG for more information what has changed recently.
Please see CONTRIBUTING for details.
If you discover any security related issues, please email [email protected] instead of using the issue tracker.
Credits
The MIT License (MIT). Please see License File for more information.