api response
v1.2.2
CoreJsonResponse JSON 响应特征。此特性使任何控制器都可以轻松返回带有适当 HTTP 状态代码的 JSON 响应。
composer require aelnemr/api-response
您所需要的只是在控制器内use CoreJsonResponse特征。
例子:
<?php
namespace App Http Controllers ;
use Illuminate Http Request ;
use AElnemr RestFullResponse CoreJsonResponse ;
class CountryController extends Controller
{
use CoreJsonResponse;
public function index ()
{
$ data = App User:: get ();
return $ this -> ok ( $ data );
}
}| 方法 | 状态码 | 描述 |
|---|---|---|
| 好的 | 200 | 获取成功,patch(返回JSON对象) |
| 确定分页 | 200 | 获取成功,patch(返回一个JSON对象) |
| 已创建 | 201 | 发布成功(返回JSON对象) |
| 方法 | 状态码 | 描述 |
|---|---|---|
| 未经验证的 | 401 | 错误未验证 |
| 禁止的 | 403 | 错误未授权(已通过身份验证,但没有权限) |
| 未找到 | 404 | 未找到错误 |
| 无效请求 | 第422章 | 错误验证 |
| 方法 | 状态码 | 描述 |
|---|---|---|
| 公认 | 第202章 | 成功发布、删除、路径 - 异步 |
| 错误的请求 | 400 | 错误 由于语法错误,服务器无法理解请求 |
| 付款必填 | 第402章 | 错误 需要付款 |
| 冲突 | 409 | 错误 逻辑错误 |