{"id":28383163,"url":"https://github.com/swisnl/json-api-client-laravel","last_synced_at":"2025-06-25T13:32:59.302Z","repository":{"id":43711829,"uuid":"343526674","full_name":"swisnl/json-api-client-laravel","owner":"swisnl","description":"A PHP package for mapping remote {json:api} resources to Eloquent like models and collections. ","archived":false,"fork":false,"pushed_at":"2025-05-28T10:17:54.000Z","size":92,"stargazers_count":8,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-06-06T05:30:34.465Z","etag":null,"topics":["client","hacktoberfest","hydration","json","json-api","laravel","laravel-package","psr"],"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/swisnl.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.md","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-03-01T19:04:54.000Z","updated_at":"2025-05-28T10:17:57.000Z","dependencies_parsed_at":"2025-03-14T13:01:21.902Z","dependency_job_id":null,"html_url":"https://github.com/swisnl/json-api-client-laravel","commit_stats":{"total_commits":47,"total_committers":3,"mean_commits":"15.666666666666666","dds":"0.12765957446808507","last_synced_commit":"966252a1c015e3e1f7c4b5f7b973a111e9b39611"},"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"purl":"pkg:github/swisnl/json-api-client-laravel","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/swisnl%2Fjson-api-client-laravel","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/swisnl%2Fjson-api-client-laravel/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/swisnl%2Fjson-api-client-laravel/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/swisnl%2Fjson-api-client-laravel/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/swisnl","download_url":"https://codeload.github.com/swisnl/json-api-client-laravel/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/swisnl%2Fjson-api-client-laravel/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":261883100,"owners_count":23224435,"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":["client","hacktoberfest","hydration","json","json-api","laravel","laravel-package","psr"],"created_at":"2025-05-30T05:12:03.458Z","updated_at":"2025-06-25T13:32:59.291Z","avatar_url":"https://github.com/swisnl.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# { json:api } Client Laravel\n\n[![PHP from Packagist](https://img.shields.io/packagist/php-v/swisnl/json-api-client-laravel.svg)](https://packagist.org/packages/swisnl/json-api-client-laravel)\n[![Latest Version on Packagist](https://img.shields.io/packagist/v/swisnl/json-api-client-laravel.svg)](https://packagist.org/packages/swisnl/json-api-client-laravel)\n[![Software License](https://img.shields.io/packagist/l/swisnl/json-api-client-laravel.svg)](LICENSE.md)\n[![Buy us a tree](https://img.shields.io/badge/Treeware-%F0%9F%8C%B3-lightgreen.svg)](https://plant.treeware.earth/swisnl/json-api-client-laravel)\n[![Build Status](https://img.shields.io/github/checks-status/swisnl/json-api-client-laravel/master?label=tests)](https://github.com/swisnl/json-api-client-laravel/actions/workflows/tests.yml)\n[![Scrutinizer Coverage](https://img.shields.io/scrutinizer/coverage/g/swisnl/json-api-client-laravel.svg)](https://scrutinizer-ci.com/g/swisnl/json-api-client-laravel/?branch=master)\n[![Scrutinizer Code Quality](https://img.shields.io/scrutinizer/g/swisnl/json-api-client-laravel.svg)](https://scrutinizer-ci.com/g/swisnl/json-api-client-laravel/?branch=master)\n[![Made by SWIS](https://img.shields.io/badge/%F0%9F%9A%80-made%20by%20SWIS-%230737A9.svg)](https://www.swis.nl)\n\nThis package contains some Laravel specific classes to make it easier to use [swisnl/json-api-client](https://github.com/swisnl/json-api-client) with Laravel.\n\n## Installation\n\n``` bash\ncomposer require swisnl/json-api-client-laravel\n```\n\nN.B. Make sure you have installed a PSR-18 HTTP Client and PSR-17 HTTP Factories before you install this package or install one at the same time e.g. `composer require swisnl/json-api-client-laravel guzzlehttp/guzzle:^7.3`.\n\n### HTTP Client\n\nWe are decoupled from any HTTP messaging client with the help of [PSR-18 HTTP Client](https://www.php-fig.org/psr/psr-18/) and [PSR-17 HTTP Factories](https://www.php-fig.org/psr/psr-17/).\nThis requires an extra package providing [psr/http-client-implementation](https://packagist.org/providers/psr/http-client-implementation) and [psr/http-factory-implementation](https://packagist.org/providers/psr/http-factory-implementation).\nTo use Guzzle 7, for example, simply require `guzzlehttp/guzzle`:\n\n``` bash\ncomposer require guzzlehttp/guzzle:^7.3\n```\n\nSee [Bind clients](#bind-clients) if you want to use your own HTTP client or use specific configuration options.\n\n### Service Provider and Facade Aliases\n\nThe required service provider and some facade aliases are automatically discovered by Laravel.\nHowever, if you've disabled package auto discover, you must add the service provider and optionally the facade aliases to your `config/app.php` file:\n\n``` php\n'providers' =\u003e [\n    ...,\n    \\Swis\\JsonApi\\Client\\Providers\\ServiceProvider::class,\n],\n'aliases' =\u003e [\n    ...,\n    'DocumentFactory' =\u003e \\Swis\\JsonApi\\Client\\Facades\\DocumentFactoryFacade::class,\n    'DocumentParser' =\u003e \\Swis\\JsonApi\\Client\\Facades\\DocumentParserFacade::class,\n    'ItemHydrator' =\u003e \\Swis\\JsonApi\\Client\\Facades\\ItemHydratorFacade::class,\n    'ResponseParser' =\u003e \\Swis\\JsonApi\\Client\\Facades\\ResponseParserFacade::class,\n    'TypeMapper' =\u003e \\Swis\\JsonApi\\Client\\Facades\\TypeMapperFacade::class,\n],\n```\n\n### Configuration\n\nThe following is the default configuration provided by this package:\n\n``` php\nreturn [\n    /*\n    |--------------------------------------------------------------------------\n    | Base URI\n    |--------------------------------------------------------------------------\n    |\n    | Specify a base uri which will be prepended to every URI.\n    |\n    | Default: empty string\n    |\n    */\n    'base_uri' =\u003e '',\n];\n```\n        \nIf you would like to make changes to the default configuration, publish and edit the configuration file:\n\n``` bash\nphp artisan vendor:publish --provider=\"Swis\\JsonApi\\Client\\Providers\\ServiceProvider\" --tag=\"config\"\n```\n\n\n## Getting started\n\nSimply let the container inject the `DocumentClient` and you're good to go!\n\n``` php\nuse Swis\\JsonApi\\Client\\DocumentClient;\n\nclass RecipeController extends Controller\n{\n    public function index(DocumentClient $client)\n    {\n        $document = $client-\u003eget('https://cms.contentacms.io/api/recipes');\n    \n        /** @var \\Swis\\JsonApi\\Client\\Collection\u0026\\Swis\\JsonApi\\Client\\Item[] $recipes */\n        $recipes = $document-\u003egetData();\n        \n        foreach ($recipes as $recipe) {\n            // Do stuff with the recipe\n        }\n    }\n}\n```\n\nTake a look at [swisnl/json-api-client](https://github.com/swisnl/json-api-client) for more usage information.\n\n### Laravel HTTP Client\n\nYou can also use the built-in [HTTP Client](https://laravel.com/docs/http-client) of Laravel if you prefer. Please note this requires Laravel 7+.\n\n``` php\nuse Illuminate\\Support\\Facades\\Http;\nuse Swis\\JsonApi\\Client\\Facades\\DocumentFactoryFacade;\nuse Swis\\JsonApi\\Client\\Item;\n\n$recipe = (new Item())\n    -\u003esetType('recipes')\n    -\u003efill([\n        'title' =\u003e 'Frankfurter salad with mustard dressing',\n    ]);\n\n$document = Http::asJsonApi() // Sets the Content-Type and Accept headers to 'application/vnd.api+json'.\n    -\u003epost('https://cms.contentacms.io/api/recipes', DocumentFactoryFacade::make($recipe))\n    -\u003ejsonApi(); // Parses the response into a JSON:API document.\n```\n\n\n## Service Provider\n\nThe `\\Swis\\JsonApi\\Client\\Providers\\ServiceProvider` registers the `TypeMapper`, `JsonApi\\Parser` and both clients; `Client` and `DocumentClient`.\nEach section can be overwritten to allow extended customization.\n\n### Bind TypeMapper\n\nThe service provider registers the `\\Swis\\JsonApi\\Client\\TypeMapper` as a singleton so your entire application has the same mappings available.\n\n#### Mapping types\n\nYou can manually register items with the `TypeMapper` or use the supplied `TypeMapperServiceProvider`:\n\n``` php\nuse Swis\\JsonApi\\Client\\Providers\\TypeMapperServiceProvider as BaseTypeMapperServiceProvider;\n\nclass TypeMapperServiceProvider extends BaseTypeMapperServiceProvider\n{\n    /**\n     * A list of class names implementing \\Swis\\JsonApi\\Client\\Interfaces\\ItemInterface.\n     *\n     * @var string[]\n     */\n    protected $items = [\n        \\App\\Items\\Author::class,\n        \\App\\Items\\Blog::class,\n        \\App\\Items\\Comment::class,\n    ];\n}\n```\n\n### Bind Clients\n\nThe service provider registers the `Client` and `DocumentClient` to your application.\nBy default the `Client` uses [php-http/discovery](https://github.com/php-http/discovery) to find an available HTTP client, request factory and stream factory so you don't have to setup those yourself.\nYou can specify your own HTTP client, request factory or stream factory by customizing the container binding.\nThis is a perfect way to add extra options to your HTTP client or register a mock HTTP client for your tests:\n\n``` php\nclass ServiceProvider extends \\Illuminate\\Support\\ServiceProvider\n{\n    public function register()\n    {\n        $this-\u003eapp-\u003ebind(\\Swis\\JsonApi\\Client\\Client::class, function ($app) {\n            if ($app-\u003eenvironment('testing')) {\n                $httpClient = new \\Swis\\Http\\Fixture\\Client(\n                    new \\Swis\\Http\\Fixture\\ResponseBuilder('/path/to/fixtures')\n                );\n            } else {\n                $httpClient = new \\GuzzleHttp\\Client(\n                    [\n                        'http_errors' =\u003e false,\n                        'timeout' =\u003e 2,\n                    ]\n                );\n            }\n    \n            return new \\Swis\\JsonApi\\Client\\Client($httpClient);\n        });\n    }\n}\n```\n\nN.B. This example uses our [swisnl/php-http-fixture-client](https://github.com/swisnl/php-http-fixture-client) when in testing environment.\nThis package allows you to easily mock requests with static fixtures.\nDefinitely worth a try!\n\n\n## Change log\n\nPlease see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.\n\n\n## Testing\n\n``` bash\ncomposer test\n```\n\n\n## Contributing\n\nPlease see [CONTRIBUTING](CONTRIBUTING.md) and [CODE_OF_CONDUCT](CODE_OF_CONDUCT.md) for details.\n\n\n## Security\n\nIf you discover any security related issues, please email security@swis.nl instead of using the issue tracker.\n\n\n## License\n\nThe MIT License (MIT). Please see [License File](LICENSE.md) for more information.\n\nThis package is [Treeware](https://treeware.earth). If you use it in production, then we ask that you [**buy the world a tree**](https://plant.treeware.earth/swisnl/json-api-client-laravel) to thank us for our work. By contributing to the Treeware forest you’ll be creating employment for local families and restoring wildlife habitats.\n\n\n## SWIS :heart: Open Source\n\n[SWIS](https://www.swis.nl) is a web agency from Leiden, the Netherlands. We love working with open source software.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fswisnl%2Fjson-api-client-laravel","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fswisnl%2Fjson-api-client-laravel","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fswisnl%2Fjson-api-client-laravel/lists"}