定制 mahmoud-birdsol/api-responses 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

mahmoud-birdsol/api-responses

Composer 安装命令:

composer require mahmoud-birdsol/api-responses

包简介

A responsable set of classes for resource api request

README 文档

README

Build Status StyleCI

This package is a response helper classes for laravel api developers to use with transformers the package we use for transformers is spatie/laravel-fractal you will find some helper classes in this package for all rest api end points but the try value is in the Index response.

  • Index Response

  • Show Response

  • Updated Response

  • Deleted Response

  • Created Response

Installation

composer require mahmoud-birdsol/api-responses

Config Paginator adapter can be configured, as well as the paginate request key.

 php artisan vendor:publish --provider="Alacrity\Responses\Providers\ResponseServiceProvider"
/**
 * Pagination config variables.
 */
'pagination_adapter' 	 	  => \League\Fractal\Pagination\IlluminatePaginatorAdapter::class,
'pagination_request_key' 	  => 'paginate',

Usage

Index Response

To return an index response from your controller you can just return a new instance of the class and pass through an eloquent model query builder and transformer. It's specifically designed that way so you can add any default queries you need to run on the model for example an authorization restriction scope that needs to exist on the model query level or a multi-tenant application in the same db you would filter the class from the backend.

return new IndexResponse(User::query(), new UserTransformer());

Front end usage You can use request params to manipulate this response through some ready made functions.

  • Pagination you can send a paginate=10 to get a paginated response from the api.
  • Filters you can use eloquent scopes to filter for example filter by user id and you have a scope method on your model public function scopeUser($query, $userId) you can easily use this from your frontend by sending a request with user={id}.
  • Sorting You can sort response data also from your frontend by just passing through latest=true or sortAsc=email or sortDesc=id and just sort using any attribute you would like to use.

Show Response

A show response is just a simple class that will transform your data using fractal and return it to the user.

return new ShowResponse($model, new ModelTransformer());

Updated Response

The updated response is very similar to the show response except that will refresh the updated model behind the scene so you can do something like this in your controller method easily.

public function update($request, User $user)
{
    $user->update($request->all());
    
    return new UpdatedResponse($user, new UserTransformer());
}

License

The MIT License (MIT). Please see License File for more information.

mahmoud-birdsol/api-responses 适用场景与选型建议

mahmoud-birdsol/api-responses 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 192 次下载、GitHub Stars 达 0, 最近一次更新时间为 2018 年 08 月 31 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 mahmoud-birdsol/api-responses 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 mahmoud-birdsol/api-responses 我们能提供哪些服务?
定制开发 / 二次开发

基于 mahmoud-birdsol/api-responses 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 192
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 2
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 2
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2018-08-31