ducascao/api-maker

使用services和repository快速创建API端点

v0.1.2 2021-05-01 02:20 UTC

This package is auto-updated.

Last update: 2024-09-29 05:49:48 UTC


README

Latest Version on Packagist Total Downloads Build Status

使用services和repository快速创建API端点。

安装

通过Composer安装

$ composer require ducascao/api-maker
  • 发布stubs以创建文件
$ php artisan api-maker:stub-publish

配置

  • 打开路由文件并注册项目路由
ApiMaker::routes();
  • 添加以下标记/** API Maker: Routes */,以便ApiMaker自动实施创建的路由
Route::group(['middleware' => 'auth:api'], function () {
    /** API Maker: Routes */
});

使用方法

  • 要使用它,只需根据配置中注册的端点进行消费即可
POST /build/project
  • 请求示例
{
  "tables": [
    {
      "name": "Template",
      "fields": [
        {
          "name": "description",
          "type": "string"
        },
        {
          "name": "path",
          "type": "string"
        }
      ]
    },
    {
      "name": "Customer",
      "fields": [
        {
          "name": "name",
          "type": "string"
        },
        {
          "name": "phone_number",
          "type": "string",
          "required": false
        },
        {
          "name": "email",
          "type": "string",
          "required": false
        },
        {
          "name": "template_id",
          "type": "unsignedInteger",
          "required": false,
          "relationship": {
            "table": "templates"
          }
        }
      ]
    }
  ]
}
  • 在config/app.php文件中注册以下提供者
/*
* Application Service Providers...
*/
App\Providers\DomainServiceProvider::class,
App\Providers\RepositoryServiceProvider::class,

注意

构建json时,请尊重表之间的关系。数组的顺序也将是迁移的顺序。

请求体(JSON)

表对象

字段对象

贡献者

许可证

MIT。请参阅许可证文件以获取更多信息。