trihydera/res
最新稳定版本:v1.1
Composer 安装命令:
composer require trihydera/res
包简介
Reponse handler for requests
README 文档
README
A helper for handling JSON and XML responses for success and error scenarios with presets of common errors to speed things up,
First made as an internal library for my API project as apart of the source but made separate to make more maintainable and use in other projects
Usage
Getting Started
Require this package, with Composer.
composer require trihydera/res
Using and creating a response instance for Json use the JsonResponse
use Trihydera\Res\JsonResponse; // Create an instance of JsonResponse $response = new JsonResponse();
And for Xml, just just use the XmlResponse instead
use Trihydera\Res\XmlResponse; // Create an instance of XmlResponse $response = new XmlResponse();
Example Success
Returning a value key in an array to say that the request was a success like Its working
$response->success([ 'value' => 'Its working' ]);
Example Error
Responding with an general error on request
$response->error('Something went wrong', '200');
For using a preset error to make things quicker, and also using your own messsage like API resource not found
// Example usage of the useError method $response->useError('NotFound'); // Example usage of the useError method with your own message $response->useError('NotFound', 'API resource not found');
Error presets
- Parameter
- Method
- NotFound
- InternalError
- Authorization
统计信息
- 总下载量: 8
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: GPL-2.0-only
- 更新时间: 2024-08-08