Package Data | |
---|---|
Maintainer Username: | oniice |
Maintainer Contact: | team@myerscode.com (myerscode) |
Package Create Date: | 2018-05-07 |
Package Last Update: | 2024-09-15 |
Home Page: | |
Language: | PHP |
License: | MIT |
Last Refreshed: | 2024-11-21 03:00:43 |
Package Statistics | |
---|---|
Total Downloads: | 17,390 |
Monthly Downloads: | 821 |
Daily Downloads: | 25 |
Total Stars: | 4 |
Total Watchers: | 2 |
Total Forks: | 0 |
Total Open Issues: | 0 |
A fluent helper to provide a consistent shaped API responses in Laravel
This package ensures your API will always return the same envelope shape, so consuming apps always know what to expect!
You can install this package via composer:
composer require myerscode/laravel-api-response
In a Laravel controller you just to build up your response and return it!
The api()
helper return a Response Builder
and as it implements the Responsable
trait you dont need to do anything more than return the builder
function resource()
{
return api()->status(201)->data(['name' => 'Foo Bar'])->message('Record Created!');
}
function resource() {
$buillder = new Builder();
$builder->status(201)->data(['name' => 'Foo Bar'])->message('Record Created!');
return $builder;
}
Would return the following JSON
response.
{
"status": 201,
"data": {
"name": "Foo Bar"
},
"meta": [],
"messages": [
"Record Created!"
]
}
The MIT License (MIT). Please see License File for more information.