定制 mixerapi/rest 二次开发

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

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

mixerapi/rest

Composer 安装命令:

composer require mixerapi/rest

包简介

The missing RESTful API component to CakePHP's bake console. Create RESTful API skeletions in seconds.

README 文档

README

Latest Version on Packagist Build Coverage Status MixerApi CakePHP Minimum PHP Version

This plugin gets your API project up and going quickly by creating routes for you.

  • Build your routes.php file from a single command or automatically expose RESTful CRUD routes with a handy AutoRouter.
  • Set default HTTP status codes for CRUD operations

This plugin assumes you have already created models and controllers. For help with the latter check out MixerApi/Bake. Check the official RESTful routing documentation for handling advanced routing scenarios not covered by this plugin.

Read more at MixerAPI.com.

Installation

!!! info "" You can skip this step if MixerAPI is installed.

composer require mixerapi/rest
bin/cake plugin load MixerApi/Rest

Alternatively after composer installing you can manually load the plugin in your Application:

# src/Application.php
public function bootstrap(): void
{
    // other logic...
    $this->addPlugin('MixerApi/Rest');
}

AutoRouter

Creating routes is already pretty easy, but AutoRouter makes building CRUD routes effortless. This is great if you are just getting started with building APIs in CakePHP.

In your routes.php simply add \MixerApi\Rest\Lib\AutoRouter:

# config/routes.php
$routes->scope('/', function (RouteBuilder $builder) {
    // ... other routes
    (new AutoRouter($builder))->buildResources();
    // ... other routes
});

This will add routes for CRUD controller actions (index, add, edit, view, and delete). If your controller does not have any CRUD methods, then the route will be skipped. AutoRouting works for plugins too:

# in your plugins/{PluginName}/routes.php file
(new AutoRouter($builder, new ResourceScanner('MyPlugin\Controller')))->buildResources();

Create Routes

While AutoRouter makes life easy, it must scan your controllers to build RESTful resources. This has a slight performance penalty. No worry, you can use mixerapi:rest route create to code your routes for you. This will write routes directly to your routes.php file.

# writes to `config/routes.php`
bin/cake mixerapi:rest route create

Use --prefix to specify a prefix:

bin/cake mixerapi:rest route create --prefix /api

Use --plugin for plugins:

# writes to `plugins/MyPlugin/config/routes.php`
bin/cake mixerapi:rest route create --plugin MyPlugin

To perform a dry-run use the --display option:

bin/cake mixerapi:rest route create --display

For non-CRUD routes, sub-resources, and advanced routing please reference the CakePHP RESTful routing documentation

List Routes

This works similar to bin/cake routes but shows only RESTful routes and improves some formatting of information.

bin/cake mixerapi:rest route list

To limit output to a specific plugin use the --plugin option:

# limit to a plugin:
bin/cake mixerapi:rest route list --plugin MyPlugin

#limit to main application:
bin/cake mixerapi:rest route list --plugin App

CRUD HTTP Status Codes

The default status codes are:

Action Status Code
index 200
view 200
add 201
edit 200
delete 204

To change these load a MixerApi.Rest.crud.statusCodes configuration:

return [
    'MixerApi' => [
        'Rest' => [
            'crud' => [
                'statusCodes' => [
                    'index' => 200,
                    'view' => 200,
                    'add' => 201,
                    'edit' => 200,
                    'delete' => 204
                ]
            ]
        ]
    ]
];

See the CakePHP documentation on loading configuration files

mixerapi/rest 适用场景与选型建议

mixerapi/rest 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 64.16k 次下载、GitHub Stars 达 3, 最近一次更新时间为 2020 年 08 月 11 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「CakePHP Rest」 「cakephp4 rest」 「cakephp rest bake」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

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

围绕 mixerapi/rest 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

  • 总下载量: 64.16k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 3
  • 点击次数: 34
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 3
  • Watchers: 1
  • Forks: 2
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-08-11