定制 mixerapi/rest 二次开发

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

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

mixerapi/rest

最新稳定版本:v2.0.4

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-01-04

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固