{"id":15916883,"url":"https://github.com/tomschlick/request-migrations","last_synced_at":"2025-04-05T22:08:42.982Z","repository":{"id":48229987,"uuid":"100408108","full_name":"tomschlick/request-migrations","owner":"tomschlick","description":"HTTP Request Migrations for API Versioning like Stripe","archived":false,"fork":false,"pushed_at":"2021-10-29T02:07:22.000Z","size":81,"stargazers_count":183,"open_issues_count":4,"forks_count":12,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-03-29T21:06:46.083Z","etag":null,"topics":["http","laravel","middleware","migrations","php","php7","requests"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tomschlick.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-08-15T18:43:09.000Z","updated_at":"2025-02-11T21:33:31.000Z","dependencies_parsed_at":"2022-08-24T10:52:15.959Z","dependency_job_id":null,"html_url":"https://github.com/tomschlick/request-migrations","commit_stats":null,"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tomschlick%2Frequest-migrations","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tomschlick%2Frequest-migrations/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tomschlick%2Frequest-migrations/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tomschlick%2Frequest-migrations/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tomschlick","download_url":"https://codeload.github.com/tomschlick/request-migrations/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247406091,"owners_count":20933803,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["http","laravel","middleware","migrations","php","php7","requests"],"created_at":"2024-10-06T18:06:14.910Z","updated_at":"2025-04-05T22:08:42.961Z","avatar_url":"https://github.com/tomschlick.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# HTTP Request Migrations\n\n[![Latest Version on Packagist](https://img.shields.io/packagist/v/tomschlick/request-migrations.svg?style=flat-square)](https://packagist.org/packages/tomschlick/request-migrations)\n[![Build Status](https://img.shields.io/travis/tomschlick/request-migrations/master.svg?style=flat-square)](https://travis-ci.org/tomschlick/request-migrations)\n[![Total Downloads](https://poser.pugx.org/tomschlick/request-migrations/downloads)](https://packagist.org/packages/tomschlick/request-migrations)\n[![StyleCI](https://styleci.io/repos/100408108/shield)](https://styleci.io/repos/100408108)\n\nThis package is based on the [API versioning scheme used at Stripe](https://stripe.com/blog/api-versioning). Users pass a version header and you automatically migrate the request \u0026 response data to match the current version of your code.\n\n## Installation\n\nYou can install the package via composer:\n\n### Installation via Composer\n\n```bash\ncomposer require tomschlick/request-migrations\n```\n### Service Provider \u0026 Facade\n\nThis package supports Laravel 5.5 autoloading so the service provider and facade will be loaded automatically. \n\nIf 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`.\n\n```php\n'providers' =\u003e [\n    \\TomSchlick\\RequestMigrations\\RequestMigrationsServiceProvider.php,\n]\n```\n```php\n'aliases' =\u003e [\n    'RequestMigrations' =\u003e \\TomSchlick\\RequestMigrations\\Facades\\RequestMigrations::class,\n]\n```\n\n### Middleware\n\nAdd the middleware to your Http Kernel `app/Http/Kernel.php`.\n\n```php\nprotected $middleware = [\n\t\\TomSchlick\\RequestMigrations\\RequestMigrationsMiddleware::class,\n];\n\n```\n\n### Configuration\n\nRun the following Artisan command to publish the package configuration to `config/request-migrations.php`.\n\n```bash\nphp artisan vendor:publish --provider=\"TomSchlick\\RequestMigrations\\RequestMigrationsServiceProvider\"\n```\n\n## Usage\n\n### Creating a Migration\n\nYou can generate a new request migration using the Artisan CLI.\n\n```shell\nphp artisan make:request-migration ExampleMigration\n\n```\n\nThe command will generate a request migration and publish it to `App/Http/Migrations/*`.\n\nIt will generate a migration, you can modify it like this:\n\n```php\nclass GroupNameMigration extends RequestMigration\n{\n    /**\n     * Migrate the request for the application to \"read\".\n     *\n     * @param \\Illuminate\\Http\\Request $request\n     *\n     * @return \\Illuminate\\Http\\Request\n     */\n    public function migrateRequest(Request $request) : Request\n    {\n        return $request;\n    }\n\n    /**\n     * Migrate the response to display to the client.\n     *\n     * @param \\Symfony\\Component\\HttpFoundation\\Response $response\n     *\n     * @return \\Symfony\\Component\\HttpFoundation\\Response\n     */\n    public function migrateResponse(Response $response) : Response\n    {\n        $content = json_decode($response-\u003egetContent(), true);\n\n        $content['firstname'] = array_get($content, 'name.firstname');\n        $content['lastname'] = array_get($content, 'name.lastname');\n        unset($content['name']);\n\n        return $response-\u003esetContent(json_encode($content));\n    }\n\n    /**\n     * Define which named paths should this migration modify.\n     *\n     * @return array\n     */\n    public function paths() : array\n    {\n        return [\n            'users/show',\n        ];\n    }\n}\n```\n\n### Override the Versions\n\n```php\nuse TomSchlick\\RequestMigrations\\Facades\\RequestMigrations;\n\n// set both response \u0026 request versions\nRequestMigrations::setVersion('2017-01-01')\n\n// set the request version\nRequestMigrations::setRequestVersion('2017-01-01')\n\n// set the response version\nRequestMigrations::setResponseVersion('2017-01-01')\n```\n\nThis can be useful if you are pinning the version to a user.\n\n```php\nRequestMigrations::setVersion(auth()-\u003euser()-\u003eapi_version);\n```\n\n## Changelog\n\nPlease see [CHANGELOG](CHANGELOG.md) for more information what has changed recently.\n\n## Testing\n\n```bash\ncomposer test\n```\n\n## Contributing\n\nPlease see [CONTRIBUTING](CONTRIBUTING.md) for details.\n\n## Security\n\nIf you discover any security related issues, please email tom@schlick.email instead of using the issue tracker.\n\n## License\n\nThe MIT License (MIT). Please see [License File](LICENSE.md) for more information.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftomschlick%2Frequest-migrations","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftomschlick%2Frequest-migrations","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftomschlick%2Frequest-migrations/lists"}