anhzf/laravel-rest-api is a Laravel package for laravel restfulapi management.
It currently has 0 GitHub stars and 7 downloads on Packagist (latest version v1.0.0).
Install it with composer require anhzf/laravel-rest-api.
Discover more Laravel packages by anhzf
or browse all Laravel packages to compare alternatives.
Last updated
Laravel Rest API management
composer require anhzf/laravel-rest-api
{
"success": true,
"message": "your message here",
"data": {
"myData": "your data here..."
},
"errors": [
"laravel", "automatically", "send", "exceptions", "here..."
]
}
APIResponse::message(string $message) use Anhzf\LaravelRestAPI\APIResponse;
// end of some controller
return APIResponse::message('[your message here]')->send();
APIResponse::data(array $data) use Anhzf\LaravelRestAPI\APIResponse;
$myData = ['foo', 'bar', 'baz'];
// end of some controller
return APIResponse::data(compact('myData'))->send();
APIResponse::statusCode(int $statusCode) use Anhzf\LaravelRestAPI\APIResponse;
// end of some controller
return APIResponse::statusCode(404)
->message('Didn\'t find matched user!')
->send();
APIResponse::error()It will send response without success key in your Json Response
use Anhzf\LaravelRestAPI\APIResponse;
// end of some controller
return APIResponse::error()
->statusCode(422)
->message('email field is required!')
->send();
By adding Send verb in above listed method, it will be send response like using send()
use Anhzf\LaravelRestAPI;
class APIResponse {
public static sendMessage(string $message);
public static sendData(array $data);
public static sendStatusCode(int $statusCode, bool $success = true);
public static sendError(string $message = null, int $statusCode = JsonResponse::HTTP_BAD_REQUEST);
}
use Anhzf\LaravelRestAPI\APIResponse;
return APIResponse::message('Fetched users data from database')
->sendData(compact('userData'));