All Projects → tomschlick → Request Migrations

tomschlick / Request Migrations

Licence: mit
HTTP Request Migrations for API Versioning like Stripe

Projects that are alternatives of or similar to Request Migrations

Blazar
Pre-Render Pages on the Fly in Laravel
Stars: ✭ 14 (-90.6%)
Mutual labels:  middleware, laravel
Has Parameters
A trait that allows you to pass arguments to Laravel middleware in a more PHP'ish way.
Stars: ✭ 149 (+0%)
Mutual labels:  middleware, laravel
Htmlcache
Laravel middleware to cache the rendered html
Stars: ✭ 35 (-76.51%)
Mutual labels:  middleware, laravel
Learning laravel kernel
Laravel核心代码学习
Stars: ✭ 789 (+429.53%)
Mutual labels:  middleware, laravel
Laravel Localize Middleware
Configurable localization middleware for your Laravel >=5.1 application
Stars: ✭ 92 (-38.26%)
Mutual labels:  middleware, laravel
Laravel Relationships Data
Migrations, seeders and factories to get up and running with various relationship types data quickly
Stars: ✭ 27 (-81.88%)
Mutual labels:  migrations, laravel
Laravel Remember Uploads
Laravel Middleware and helper for remembering file uploads during validation redirects
Stars: ✭ 67 (-55.03%)
Mutual labels:  middleware, laravel
Defender
Roles & Permissions for Laravel 8 / 7 / 6 / 5
Stars: ✭ 403 (+170.47%)
Mutual labels:  middleware, laravel
Depictr
A middleware for rendering static pages when crawled by search engines
Stars: ✭ 92 (-38.26%)
Mutual labels:  middleware, laravel
Laravel Analytics
Analytics for the Laravel framework.
Stars: ✭ 91 (-38.93%)
Mutual labels:  middleware, laravel
Laravel Caffeine
Keeping Your Laravel Forms Awake.
Stars: ✭ 723 (+385.23%)
Mutual labels:  middleware, laravel
L5 Very Basic Auth
Stateless HTTP basic auth for Laravel without the need for a database.
Stars: ✭ 127 (-14.77%)
Mutual labels:  middleware, laravel
Curl
Custom PHP curl library for the Laravel 5 framework - developed by Ixudra
Stars: ✭ 537 (+260.4%)
Mutual labels:  laravel, requests
Middlewares
💥 Middlewares / Relay / PSR-7 support to Nette Framework (@nette)
Stars: ✭ 13 (-91.28%)
Mutual labels:  middleware, requests
Iris
The fastest HTTP/2 Go Web Framework. AWS Lambda, gRPC, MVC, Unique Router, Websockets, Sessions, Test suite, Dependency Injection and more. A true successor of expressjs and laravel | 谢谢 https://github.com/kataras/iris/issues/1329 |
Stars: ✭ 21,587 (+14387.92%)
Mutual labels:  middleware, laravel
Laravel Smart
Automatic Migrations, Validation and More
Stars: ✭ 48 (-67.79%)
Mutual labels:  migrations, laravel
Laravel Http2serverpush
A HTTP2 SeverPush Middleware for Laravel 5
Stars: ✭ 294 (+97.32%)
Mutual labels:  middleware, laravel
Jwt Auth Guard
JWT Auth Guard for Laravel and Lumen Frameworks.
Stars: ✭ 319 (+114.09%)
Mutual labels:  middleware, laravel
Go Web
A new Golang MVC Framework. Like Laravel... but faster!
Stars: ✭ 79 (-46.98%)
Mutual labels:  middleware, laravel
Laravel Migrations Organiser
A Laravel package to help organise migrations
Stars: ✭ 96 (-35.57%)
Mutual labels:  migrations, laravel

HTTP Request Migrations

Latest Version on Packagist Build Status Total Downloads StyleCI

This package is based on the API versioning scheme used at Stripe. Users pass a version header and you automatically migrate the request & response data to match the current version of your code.

Installation

You can install the package via composer:

Installation via Composer

composer require tomschlick/request-migrations

Service Provider & Facade

This package supports Laravel 5.5 autoloading so the service provider and facade will be loaded automatically.

If you are using an earlier version of Laravel or have autoloading disabled you need to add the service provider and facade to config/app.php.

'providers' => [
    \TomSchlick\RequestMigrations\RequestMigrationsServiceProvider.php,
]
'aliases' => [
    'RequestMigrations' => \TomSchlick\RequestMigrations\Facades\RequestMigrations::class,
]

Middleware

Add the middleware to your Http Kernel app/Http/Kernel.php.

protected $middleware = [
	\TomSchlick\RequestMigrations\RequestMigrationsMiddleware::class,
];

Configuration

Run the following Artisan command to publish the package configuration to config/request-migrations.php.

php artisan vendor:publish --provider="TomSchlick\RequestMigrations\RequestMigrationsServiceProvider"

Usage

Creating a Migration

You can generate a new request migration using the Artisan CLI.

php artisan make:request-migration ExampleMigration

The command will generate a request migration and publish it to App/Http/Migrations/*.

It will generate a migration, you can modify it like this:

class GroupNameMigration extends RequestMigration
{
    /**
     * Migrate the request for the application to "read".
     *
     * @param \Illuminate\Http\Request $request
     *
     * @return \Illuminate\Http\Request
     */
    public function migrateRequest(Request $request) : Request
    {
        return $request;
    }

    /**
     * Migrate the response to display to the client.
     *
     * @param \Symfony\Component\HttpFoundation\Response $response
     *
     * @return \Symfony\Component\HttpFoundation\Response
     */
    public function migrateResponse(Response $response) : Response
    {
        $content = json_decode($response->getContent(), true);

        $content['firstname'] = array_get($content, 'name.firstname');
        $content['lastname'] = array_get($content, 'name.lastname');
        unset($content['name']);

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

    /**
     * Define which named paths should this migration modify.
     *
     * @return array
     */
    public function paths() : array
    {
        return [
            'users/show',
        ];
    }
}

Override the Versions

use TomSchlick\RequestMigrations\Facades\RequestMigrations;

// set both response & request versions
RequestMigrations::setVersion('2017-01-01')

// set the request version
RequestMigrations::setRequestVersion('2017-01-01')

// set the response version
RequestMigrations::setResponseVersion('2017-01-01')

This can be useful if you are pinning the version to a user.

RequestMigrations::setVersion(auth()->user()->api_version);

Changelog

Please see CHANGELOG for more information what has changed recently.

Testing

composer test

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please email [email protected] instead of using the issue tracker.

License

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

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].