pickmap/response
最新稳定版本:0.2.0
Composer 安装命令:
composer require pickmap/response
包简介
A Responder for all REST FULL api outputs
README 文档
README
Most of the time we need the same output structure for all REST FULL API responses.
In this package, based on the rules of the link below (jsend), you can send your response in a standard way https://github.com/omniti-labs/jsend
| Type | Description | Required Keys | Optional Keys |
|---|---|---|---|
| success | All went well, and (usually) some data was returned. | status, data | |
| fail | There was a problem with the data submitted, or some pre-condition of the API call wasn't satisfied | status, data | |
| error | An error occurred in processing the request, i.e. an exception was thrown | status, message | code, data |
How to use this package ?
step #1
Install the package with the following command
composer require pickmap/response
step #3
Go to this path in your Laravel project app/Exceptions/Handler.php and put this codes
use Pickmap\Responder\Res;
public function render($request, Throwable $e) { if ($e instanceof ModelNotFoundException) { return Res::error('not found',null,404); } elseif ($e instanceof ValidationException) { return Res::error($e->getMessage(),null,422); } return parent::render($request, $e); }
step #3
now you can use like this
Res::success($objectData); Res::success($arrayData,201); Res::error('create faild'); Res::error('new error',419); Res::fail($data); Res::response($status,$message,$data,$code);
统计信息
- 总下载量: 541
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 0
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-08-10