承接 bbrothers/http-transitions 相关项目开发

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

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

bbrothers/http-transitions

Composer 安装命令:

composer require bbrothers/http-transitions

包简介

API versioning with transition stages (migrations) based on a request header.

README 文档

README

Latest Version on Packagist Software License Build Status Coverage Status Quality Score Total Downloads

A package for transitioning HTTP requests and responses based on a version header.

Release updates to your API schema without breaking existing clients by creating Transition classes that transition the request and/or response to match the previously expected result. Each layer of transitions only needs to convert the current version to match the previous version, from there the request and response will be piped through the subsequent layers until they match the version requested in the Api-Version header.

Largely based on Stripe's API versioning article.

Install

$ composer require bbrothers/http-transitions

Middleware

In your app/Http/Kernel.php file, add:

protected $middleware = [
    Transitions\TransitionMiddleware::class
];

Service Provider

For Laravel 5.4, in your config/app.php file, in the providers array, add:

Transitions\TransitionProvider::class

Publish Config

php artisan vendor:publish --provider="Transitions\TransitionProvider"

Usage

Add version numbers and an array of Transition classes to the transitions.php file.

return [
   'headerKey' => 'Api-Version',
   'transitions'    => [
       '20160101' => [
           FullNameToNameTransition::class,
           NameToFirstNameLastNameTransition::class,
           BirthDateTransition::class,
       ],
       '20150101' => [
           FirstNameLastNameToFullNameTransition::class,
       ],
   ],
]

Create a transition:

class NameToFirstNameLastNameTransition extends Transition
{

    public function transformResponse(Response $response) : Response
    {
        $content = json_decode($response->getContent(), true);
        $content = array_diff_key(array_merge($content, $content['name']), ['name' => true]);

        return $response->setContent(json_encode($content));
    }
}

Transition Generators

$ php artisan make:transition NameToFirstNameLastNameTransition

Optionally, the --request-only or --response-only flags can be added to create a transform that only generates a transformRequest or transformResponse method respectively.

Change log

Please see CHANGELOG for more information on what has changed recently.

License

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

统计信息

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

GitHub 信息

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

其他信息

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

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固