Download the PHP package lukepolo/laravel-api-migrations without Composer
On this page you can find all versions of the php package lukepolo/laravel-api-migrations. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download lukepolo/laravel-api-migrations
More information about lukepolo/laravel-api-migrations
Files in lukepolo/laravel-api-migrations
Package laravel-api-migrations
Short Description Migrations for your API
License MIT
Homepage https://github.com/lukepolo/laravel-api-migrations
Informations about the package laravel-api-migrations
Laravel API Migrations
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.
TLDR
You can update your API without worrying of users applications breaking with API Migrations.
You write these incrementing migrations to convert your request/responses go back in time to allow your users applications to work flawlessly.
Features
- User Version Pinning
- Major API Versioning Supported
- Convention Supplied with artisan commands
How to use in day to day development
You should create releases (including your current release) when releasing your API. This allows the system to know how to migrate a request/response to and older version of the API.
For example :
Current Release V1 - 2017-08-31 expects the response :
Release V1 - 2017-08-01 expects the response :
When your users are using the older API they expect to see that secret title.
It will then migrate the request 2017-08-31 to 2017-08-01.
While this is a simple example you can see the power with these migrations to create simple steps to migrate your current version of the api to an older version of the API very easily.
Installation
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
.
Middleware
Add the middleware to your Http Kernel app/Http/Kernel.php
.
You have a couple of choices where to put this, recommenced under the api middleware!
Configuration
Run the following Artisan command to publish the package configuration to config/request-migrations.php
.
Usage
Creating a Release
You can generate a new release using the Artisan CLI.
Creating a Migration
You can generate a new api migration using the Artisan CLI.
The command will generate a api migration and publish it to App/Http/ApiMigrations/V{VersionNumber}/Release_{YYYY_MM_DD}/{MigrationName}
.
Caching Migrations
Once you move to prod you should cache the results
Making HTTP Requests
By default when making a request to your API it will not run any migrations.
To use a different version of your api just attach a header :
Writing the API migrations
migrateRequest
method : This is used to convert your request to be valid to your most current route
migrateResponse
method : This is used to convert your response to what you should expect for that version
Example : -- link to gist --
Versioning
You should use the artisan commands above to create releases, including your current release. You can also set your current versions in the config.
You can tag your current versions in your config by setting it up like this :
``### User Version Pinning With version pinning you can automatically keep users to that API and allow them to upgrade to your latest version at their convince. Once once your user hits your api for the first time it will set the most current version.
!!!! NOTE !!!!!
You must also make the column api_version
fillable in your User
model!
Changelog
Please see CHANGELOG for more information what has changed recently.
Testing
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.
Credits
This package was original idea build by Tom Schlick, but modified heavily.
All versions of laravel-api-migrations with dependencies
illuminate/config Version 5.4.*|5.5.*
illuminate/contracts Version 5.4.*|5.5.*
illuminate/http Version 5.4.*|5.5.*
illuminate/support Version 5.4.*|5.5.*