Download the PHP package yuanzhihai/think-response without Composer
On this page you can find all versions of the php package yuanzhihai/think-response. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Table of contents
Download yuanzhihai/think-response
More information about yuanzhihai/think-response
Files in yuanzhihai/think-response
Download yuanzhihai/think-response
More information about yuanzhihai/think-response
Files in yuanzhihai/think-response
Vendor yuanzhihai
Package think-response
Short Description thinkphp api 项目提供一个规范统一的响应数据结构
License MIT
Package think-response
Short Description thinkphp api 项目提供一个规范统一的响应数据结构
License MIT
Please rate this library. Is it a good library?
Informations about the package think-response
think-response
为 thinkphp API 项目提供一个规范统一的响应数据格式。
介绍
为 thinkphp API 项目提供一个规范统一的响应数据格式。
think-response
主要用来统一 API 开发过程中「成功」、「失败」以及「异常」情况下的响应数据格式。
遵循一定的规范,返回易于理解的 HTTP 状态码,并支持定义 ResponseCodeEnum
来满足不同场景下返回描述性的业务操作码。
概览
- 统一的数据响应格式,固定包含:
code
、status
、data
、message
、error
(响应格式设计源于:RESTful服务最佳实践 ) - 你可以继续链式调用
Response
类中的所有 public 方法,比如Response::success()->header('X-foo','bar');
- 合理地返回 Http 状态码,默认为 restful 严格模式,可以配置异常时返回 200 http 状态码(多数项目会这样使用)
- 根据 debug 开关,合理返回异常信息、验证异常信息等
- 支持修改 Thinkphp 特地异常的状态码或提示信息,比如将
No query results for model
的异常提示修改成数据未找到
- 支持配置返回字段是否显示,以及为她们设置别名,比如,将
message
别名设置为msg
,或者 分页数据第二层的data
改成list
(res.data.data -> res.data.list) - 内置 Http 标准状态码支持,同时支持扩展 ResponseCodeEnum 来根据不同业务模块定义响应码(可选,需要安装
yuanzhihai/think-enum
) - 响应码 code 对应描述信息 message 支持本地化,支持配置多语言(可选,需要安装
yuanzhihai/think-enum
)
安装
使用
成功响应
示例代码
返回全部数据
支持自定义内层 data 字段名称,比如 rows、list
分页数据
支持自定义内层 data 字段名称,比如 rows、list
返回单条数据
其他快捷方法
失败响应
不指定 message
-
未配置多语言响应描述
- 配置多语言描述
指定 message
返回数据
指定 code
返回数据
其他快捷方法
异常响应
表单验证异常
自定义业务码
本地化业务码描述
协议
MIT 许可证(MIT)。有关更多信息,请参见协议文件。
All versions of think-response with dependencies
PHP Build Version
Package Version
Requires
php Version
^8.0.2
ext-json Version *
ext-json Version *
The package yuanzhihai/think-response contains the following files
Loading the files please wait ....