2017 © Pedro Peláez
 

library http-transitions

HTTP Schema Version Transitioning

image

bbrothers/http-transitions

HTTP Schema Version Transitioning

  • Tuesday, March 13, 2018
  • by bbrothers
  • Repository
  • 1 Watchers
  • 1 Stars
  • 3,726 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 7 Versions
  • 29 % Grown

The README.md

http-transitions

Latest Version on Packagist ![Software License][ico-license] Build Status ![Coverage Status][ico-scrutinizer] Quality Score ![Total Downloads][ico-downloads], (*1)

A package for transitioning HTTP requests and responses based on a version header., (*2)

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., (*3)

Largely based on Stripe's API versioning article., (*4)

Install

``` bash $ composer require bbrothers/http-transitions, (*5)

#### Middleware

In your `app/Http/Kernel.php` file, add:
```php
protected $middleware = [
    Transitions\TransitionMiddleware::class
];

Service Provider

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

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., (*7)

``` php return [ 'headerKey' => 'Api-Version', 'transitions' => [ '20160101' => [ FullNameToNameTransition::class, NameToFirstNameLastNameTransition::class, BirthDateTransition::class, ], '20150101' => [ FirstNameLastNameToFullNameTransition::class, ], ], ], (*8)

Create a transition:
```php
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., (*9)

Change log

Please see CHANGELOG for more information on what has changed recently., (*10)

License

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

The Versions

18/09 2017

dev-feature/add-console-generators

dev-feature/add-console-generators https://github.com/bbrothers/http-transitions

HTTP Schema Version Transitioning

  Sources   Download

MIT

The Requires

 

The Development Requires

api middleware schema http versioning transition