承接 alexpensato/laravel-api-maker 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

alexpensato/laravel-api-maker

Composer 安装命令:

composer require alexpensato/laravel-api-maker

包简介

Automate the generation of your REST APIs

README 文档

README

Automate the generation of your REST APIs with the console generator command make:api

Introduction

This package is an extended version of the laravel-api-generator package. It includes a completely rewritten BaseController, now renamed to ApiController. This package also presents two new controller types: ReadOnlyController, for APIs that don't need writing capabilities; and WebController, for applications that need support for frontend scaffolding views.

This package relies on the Repository Design Pattern, which means that Controllers will access Models through a Repository interface, which provides better separation of concerns for data access methods and business rules. This repository implementation was inspired by Connor Leech's and Jeff Decena's articles.

This package also uses Codeception/Specify and Codeception/Verify packages to get you started with BDD-style unit testing.

This enhanced version of the console generator creates the following files for each Model in one single command:

  1. ApiController extended class

  2. Fractal Transformer class

  3. Repository interface

  4. Repository implementation class

  5. Unit test file configured for BDD

It also modifies the following configuration files:

  1. Adds routes to routes/api.php

  2. Adds repository binding to ApiServiceProvider

This package was designed to get you started with professional REST API best practices.

Compatibility

Laravel API Maker Laravel
1.0.x 5.6
1.1.x 5.7

Installation

Step 1 - Run composer require alexpensato/laravel-api-maker

Step 2 - Copy the ApiServiceProvider class to app/Providers folder:

cp -R vendor/alexpensato/laravel-api-maker/templates/Providers app/Providers

and check what you got there.

Step 3 - Register the service providers in the config/app.php configuration file

<?php

'providers' => [
    
    ...
    
    /*
     * Package Service Providers...
     */
    
    Pensato\Api\ServiceProvider::class,
    
    /*
     * Application Service Providers...
     */
    
    App\Providers\ApiServiceProvider::class,
],
?>

Step 4 - Laravel already provides an API routes file. To correctly configure the console generator automation process, you need to choose one of the routing templates presented in vendor/alexpensato/laravel-api-maker/templates/routes/api.php, and then copy it to your project's api routing file.

For instance, copy the code below to the end of your routes/api.php project file.

<?php

Route::group(['prefix' => 'v1'], function () {
    //
});

It will allow the console generator to automatically inject resources routes to the api routing file.

Usage

Generator

The only console command that is added and needed is artisan make:api <ModelName>.

Imagine you need to create a rest api to list/create/update etc. users from users table. To achieve that you need to do lots of boilerplate operations - create controller, transformer, repository, unit testing, set up needed routes and configuring repository binding.

php artisan make:api User does all the work for you.

It is important to notice that this command assumes that Model has already been created in the Models folder.

For instance, you can create a Model using the following command:

php artisan make:model -mf Models/<ModelName>

Conventions

You may have noticed that the Controller which has just been generated includes two public methods: __constructor() and transformer(). That's because those methods are the only thing that you need in your controller to set up a basic REST API.

The list of routes that are available out-of-the-box:

  1. GET api/v1/users
  2. GET api/v1/users/{id}
  3. POST api/v1/users
  4. PUT api/v1/users/{id}
  5. DELETE api/v1/users/{id}

Request and response formats are JSON. Response format is defined by Fractal.

Fractal includes are supported via $_GET['include'].

Validation rules for create and update can be set by overwriting rulesForCreate and rulesForUpdate in your controller.

Contributions

…are always welcome. Don’t hesitate to submit a bug report or a pull request.

When filling a bug report or submitting a new feature, please try including supporting test cases.

License

This project is licensed under MIT license.

Although it is a tested package, use at your risk!

alexpensato/laravel-api-maker 适用场景与选型建议

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

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

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

围绕 alexpensato/laravel-api-maker 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

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