定制 mkd/laravel-fast-api 二次开发

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

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

mkd/laravel-fast-api

Composer 安装命令:

composer require mkd/laravel-fast-api

包简介

Laravel FastAPI is a PHP attribute-based routing package designed to streamline API development. It enables developers to define routes, methods, and middlewares directly within their controllers using simple PHP attributes. By reducing the complexity of traditional route definition, Laravel FastAPI

README 文档

README

Latest Version Issues License

Laravel FastAPI is a PHP attribute-based routing solution for building APIs quickly and efficiently. With FastAPI attributes, you can define routes, methods, and middlewares directly in your controller classes, reducing the need for complex route files and enabling better organization and clarity.

This package also integrates seamlessly with Laravel's route:cache for enhanced performance, ensuring your APIs are as fast as possible.

Features

  • Attribute-Based Routing: Define your API routes using PHP attributes.
  • Support for Advanced Routing Options: Middleware, where clauses, route options, and more!
  • Enum-Based HTTP Methods: Use the predefined FastApiMethod for your HTTP methods.
  • API Caching: Leverage Laravel's route:cache for optimal performance.
  • Clear API Cache: Quickly clear cached API routes with simple Artisan commands.

Installation

You can install the package via Composer:

composer require mkd/laravel-fast-api

Usage

Define FastAPI Routes

Use the #[FastAPIGroup] and #[FastAPI] attributes to define routes inside your controller classes.

use MKD\FastAPI\Attributes\FastAPI;
use MKD\FastAPI\Attributes\FastAPIGroup;

#[FastAPIGroup(prefix: '/items', options: ['name' => 'items'], middlewares: ['auth'])]
class ItemsController extends Controller
{
    #[FastAPI(method: FastApiMethod::GET, path: '/data/{id}', options: ['functions' => [
        'whereIn' => ['id', ['2']],
    ], 'name' => 'item_id'])]
    public function getItem($id)
    {
        return response()->json(['item' => $id]);
    }
}

This simple attribute-based approach automatically handles routing logic, allowing you to focus on building your API logic.

Supported Methods and Functions

You can define routes with the following HTTP methods:

enum FastApiMethod
{
    case GET;
    case POST;
    case PUT;
    case PATCH;
    case OPTION;
    case DELETE;
    case ANY;
    case REDIRECT;
    case MATCH;
}

In addition, you can leverage these functions to customize your routes:

private array $supportedFunctions = [
    'middleware',
    'where',
    'whereNumber',
    'whereAlpha',
    'whereAlphaNumeric',
    'whereUuid',
    'whereUlid',
    'whereIn',
    'name',
    'withTrashed',
    'scopeBindings',
    'withoutScopedBindings',
];

Configurations

In your configuration file, you can specify paths and controllers to be scanned for FastAPI attributes.

return [
    //Paths to check for controllers that use fast-api
    'paths' => [
        app_path('Http/Controllers'),
    ],

    //Specify controllers that are not included in the paths
    'controllers' => [
        \App\Http\Controllers\CustomController::class
    ],
];

Artisan Commands

FastAPI provides useful commands for caching and clearing controllers:

  • Cache the controllers for better scanning performance:

    php artisan fast-api:cache
  • Clear the cached controllers:

    php artisan fast-api:clear-cache

Performance

By using Laravel's route:cache, the FastAPI routes are cached to ensure high performance. It is recommended to always cache your routes in production environments for faster API responses.

php artisan route:cache

Contributing

Feel free to submit issues and pull requests. Contributions are welcome!

License

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

mkd/laravel-fast-api 适用场景与选型建议

mkd/laravel-fast-api 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 8 次下载、GitHub Stars 达 12, 最近一次更新时间为 2024 年 10 月 16 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

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

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-10-16