mrgarest/echo-api
Composer 安装命令:
composer require mrgarest/echo-api
包简介
A simple package for generating API responses in Laravel
README 文档
README
⚠️ THIS LIBRARY IS NO LONGER SUPPORTED AND WILL SOON BE REMOVED!!!
A simple package for generating API responses in Laravel.
Installation
You can install the package via composer:
composer require mrgarest/echo-api
Examples
Below are some examples using the methods for different responses.
Success
To create a successful JSON response, you can use the method:
return EchoApi::success();
Response result:
{
"success": true
}
Adding additional data
If you want to add additional data to the response, you can pass an array with data to the success() method.
$data = [ 'user' => [ 'id' => 21314, 'role' => 'user', 'email' => 'email@example.com' ] ]; return EchoApi::success($data);
Response result:
{
"success": true,
"user": {
"id": 21314,
"role": "user",
"email": "email@example.com"
}
}
Error
To create a JSON response with the HTTP error code, you can use the method:
$httpStatus = Response::HTTP_NOT_FOUND; // 404 Not Found return EchoApi::httpError($httpStatus);
Response result:
{
"success": false,
"error": {
"code": 404,
"message": "Bad Request"
}
}
Custom error
If the standard HTTP error codes are not enough for you, you can use your own by creating them in the config/echo-api.php file.
return EchoApi::findError('EXAMPLE');
Response result:
{
"success": false,
"error": {
"code": "EXAMPLE",
"message": "Example of error data structure"
}
}
To get echo-api.php, don't forget to run php artisan vendor:publish.
Adding additional data
As with the success() method, you can add additional data to the responses for the httpError() and findError() methods.
$data = [ 'error' = [ 'uuid' => '21e38f4d-3be8-457c-98da-3059a947e75b' ], 'count' => 0, 'data' => null ]; return EchoApi::httpError(Response::HTTP_NOT_FOUND, $data);
Response result:
{
"success": false,
"error": {
"code": 404,
"message": "Bad Request",
"uuid": "21e38f4d-3be8-457c-98da-3059a947e75b"
},
"count": 0,
"data": null
}
mrgarest/echo-api 适用场景与选型建议
mrgarest/echo-api 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 332 次下载、GitHub Stars 达 0, 最近一次更新时间为 2024 年 09 月 19 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「php」 「json」 「api」 「response」 「laravel」 「Garest」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 mrgarest/echo-api 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 mrgarest/echo-api 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 mrgarest/echo-api 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Kinikit - PHP Application development framework MVC component
ext-json wrapper with sane defaults
A package to cast json fields, each sub-keys is castable
A PSR-7 compatible library for making CRUD API endpoints
swagger-php - Generate interactive documentation for your RESTful API using phpdoc annotations
Get wordpress nav menus and share the main site menus with the child sites.
统计信息
- 总下载量: 332
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 20
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-09-19