A minimal package for JSON Response API and HTML Response (Commingsoon) to clients, Laravel.
Download package dengan composer
composer require akilsagitarius/message
or
{
"require": {
"akilsagitarius/message" : "dev-master"
}
}
This package makes use of Laravel's auto-discovery of service providers. If you are an using earlier version of Laravel (< 5.4) you will need to manually register the service provider.
Add akilsagitarius\message\MessageServiceProvider::class
to the providers
array in config/app.php
.
example
'providers' => [
....
akilsagitarius\message\MessageServiceProvider::class,
]
Now, publish the configuration code response to your provider
php artisan vendor:publish --tag=public --force
NOTE: The response code returned in the body payload will be set as the actual HTTP header response code as well.
This is simple response
Route::get('/message', function () {
$reuslt = Message::success(200)->get();
return $reuslt;
});
Will result in the following structured result:
{
code: 200,
result: "Success",
message: "OK"
}
This is response with result your send
Route::get('/mess', function () {
$array = array(
'first' => 'This is first data',
'second' => 'This is second data',
);
$reuslt = Message::success(200)->payload($array)->get();
return $reuslt;
});
Will result in the following structured result:
{
code: 200,
result: "Informational",
message: "OK",
payload: {
first: "This is first data",
second: "This is second data"
}
}
*Muhammad Akil - Initial work - Akill
- Hat tip to anyone whose code was used
- Inspiration
- etc