定制 randomstate/laravel-api 二次开发

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

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

randomstate/laravel-api

Composer 安装命令:

composer require randomstate/laravel-api

包简介

Integration of randomstate/api with Laravel

README 文档

README

Laravel Integration for randomstate/api.

Note, for a framework agnostic starter, use randomstate/api. You will need to do some significant wiring up to make it as useful as this Laravel package.

What it does

LaravelApi is an API versioning package that allows you to namespace and version your APIs (web, ajax, rest etc) easily. It comes with out of the box support and integration for the fantastic league/fractal package.

In essence, this package allows you to standardise the output of your API while maintaining flexibility; using namespaces to change context. Add to that the fact you can version your API responses to target particular users, and you have the start to a blissful API building experience.

Installation and Setup

composer require randomstate/laravel-api

Add \RandomState\LaravelApi\LaravelApiServiceProvider::class to your app.php config file.

Publish the configuration file by running: php artisan vendor:publish --tag=laravel-api

Because of the deep routing integration required to make the magic work, you need to replace the Http Kernel with the one provided in this package. You should change the app/Http/Kernel.php class to extend RandomState\LaravelApi\Http\Kernel instead of the HttpKernel default.

Namespace Setup

To namespace your routes, you can utilise the RandomsState\LaravelApi\Http\Middleware\ApiNamespace middleware class. Add the following to the $routeMiddleware property on your Kernel class.

protected $routeMiddleware = [
    'auth' => \Illuminate\Auth\Middleware\Authenticate::class,
    // ...
    'namespace' => RandomsState\LaravelApi\Http\Middleware\ApiNamespace::class,
];

Usage

Namespacing

If you followed the setup instructions you will have added a 'namespace' middleware. You can use this as so:

Route::group(['middleware' => ['namespace:web'], function() {});
Route::group(['middleware' => ['namespace:web,1.0'], function() {}); // Forces version 1.0 to be used (must be specified in your laravel-api.php config file.

Dynamic Versioning

Since the intended use case for this package is to dynamically provide your API depending on your users' target version, I recommend the following way of versioning your routes automatically: In a service provider register method, (such as AppServiceProvider), you can add the following:

$this->app->bind(\RandomState\LaravelApi\VersionSwitch::class, function() {
    return new class implements \RandomState\LaravelApi\VersionSwitch::class {
        public function getVersionIdentifier() {
            return Auth::user()->getApiVersion();
        }
    }
});

You must implement the storage and getApiVersion method yourself - this is just an example of how you could do it.

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

randomstate/laravel-api 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.93k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2017 年 09 月 06 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2017-09-06