{"id":36982163,"url":"https://github.com/czim/laravel-jsonapi","last_synced_at":"2026-01-13T22:52:04.908Z","repository":{"id":56960955,"uuid":"47975659","full_name":"czim/laravel-jsonapi","owner":"czim","description":"Basic setup framework for creating a Laravel JSON-API server","archived":true,"fork":false,"pushed_at":"2020-03-10T09:30:35.000Z","size":318,"stargazers_count":16,"open_issues_count":3,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-12-21T00:43:11.766Z","etag":null,"topics":["encoding-responses","json-api","laravel","validation"],"latest_commit_sha":null,"homepage":null,"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/czim.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-12-14T13:07:45.000Z","updated_at":"2023-01-28T09:18:42.000Z","dependencies_parsed_at":"2022-08-21T05:10:20.790Z","dependency_job_id":null,"html_url":"https://github.com/czim/laravel-jsonapi","commit_stats":null,"previous_names":[],"tags_count":43,"template":false,"template_full_name":null,"purl":"pkg:github/czim/laravel-jsonapi","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/czim%2Flaravel-jsonapi","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/czim%2Flaravel-jsonapi/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/czim%2Flaravel-jsonapi/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/czim%2Flaravel-jsonapi/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/czim","download_url":"https://codeload.github.com/czim/laravel-jsonapi/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/czim%2Flaravel-jsonapi/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28402176,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-13T14:36:09.778Z","status":"ssl_error","status_checked_at":"2026-01-13T14:35:19.697Z","response_time":56,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["encoding-responses","json-api","laravel","validation"],"created_at":"2026-01-13T22:52:04.832Z","updated_at":"2026-01-13T22:52:04.890Z","avatar_url":"https://github.com/czim.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Latest Version on Packagist][ico-version]][link-packagist]\n[![Software License][ico-license]](LICENSE.md)\n[![Build Status](https://travis-ci.org/czim/laravel-jsonapi.svg?branch=master)](https://travis-ci.org/czim/laravel-jsonapi)\n[![Coverage Status](https://coveralls.io/repos/github/czim/laravel-jsonapi/badge.svg?branch=master)](https://coveralls.io/github/czim/laravel-jsonapi?branch=master)\n\n# JSON-API Base\n\nBasic application elements for JSON-API projects.\n\nOffers means for quickly scaffolding JSON-API compliance for Laravel applications.\n\nThis does *NOT* provide the means to set up the API or the means for user authorisation.\n\n## Disclaimer\n\nThis is very much a work in progress at this time. Interface- and other breaking changes may happen.  \nThe old, discontinued version of this project is in the `0.9.5` branch.\n\n\n## Version Compatibility\n\n Laravel      | Package \n:-------------|:--------\n 5.3          | 1.3\n 5.4 to 5.6   | 1.4\n 5.7 to 6.0   | 1.5\n \n Note that version 1.5+ requires PHP 7.1.3+ and czim/laravel-dataobject 2.0+.\n\n\n## Changelog\n\n[View the changelog](CHANGELOG.md).\n\n\n## Installation\n\nVia Composer\n\n``` bash\n$ composer require czim/laravel-jsonapi\n```\n\nAdd the `JsonApiServiceProvider` to your `config/app.php`:\n\n``` php\nCzim\\JsonApi\\Providers\\JsonApiServiceProvider::class,\n```\n\nPublish the configuration file.\n\n``` bash\nphp artisan vendor:publish\n```\n\n\n### Exceptions\n\nIn your `App\\Exceptions\\Handler`, change the `render()` method like so:\n\n```php\n\u003c?php\n\n    public function render($request, Exception $exception)\n    {\n        if (is_jsonapi_request() || $request-\u003ewantsJson()) {\n            return jsonapi_error($exception);\n        }\n        \n        // ...\n```\n\nThis will render exceptions thrown for all JSON-API (and JSON) requests as JSON-API error responses.\n\n\n### Middleware\n\nTo enforce correct headers, add the `Czim\\JsonApi\\Http|Middleware\\JsonApiHeaders` middleware\nto the middleware group or relevant routes. You can do this by adding it to your `App\\Http\\Kernel` class:\n \n```php\n\u003c?php\n    protected $middlewareGroups = [\n        'api' =\u003e [\n            // ... \n            \\Czim\\JsonApi\\Http\\Middleware\\RequireJsonApiHeader::class,\n        ],\n    ];\n```\n\nNote that this *will* block access to any consumers of your API that do not conform their HTTP header use\nto the JSON-API standard.\n \n\n\n## Documentation\n\n### Request Data\n\n#### Request Query String Data\n\nJSON-API suggests passing in filter and page data using `GET` parameters, such as:\n\n```\n{API URL}?filter[id]=13\u0026page[number]=2\n```\n\nThis package offers tools for accessing this information in a standardized way:\n\nUsing the `jsonapi_query()` global helper function. \nThis returns the singleton instance of `Czim\\JsonApi\\Support\\Request\\RequestParser`.\n\n```php\n\u003c?php\n    // Get the full filter data associative array.\n    $filter = jsonapi_query()-\u003egetFilter();\n    \n    // Get a specific filter key value, if it is present (with a default fallback).\n    $id = jsonapi_query()-\u003egetFilterValue('id', 0);\n    \n    // Get the page number.\n    $page = jsonapi_query()-\u003egetPageNumber();\n```\n\nYou can ofcourse also instantiate the request parser yourself to access these methods:\n\n```php\n\u003c?php\n    // Using the interface binding ...\n    $jsonapi = app(\\Czim\\JsonApi\\Contracts\\Support\\Request\\RequestQueryParserInterface::class);\n    \n    // Or by instantiating it manually ...\n    $jsonapi = new \\Czim\\JsonApi\\Support\\Request\\RequestQueryParser(request());\n    \n    // After this, the same methods are available\n    $id = $jsonapi-\u003egetFilterValue('id');\n```\n\n#### Request Body Data\n\nFor `PUT` and `POST` requests with JSON-API formatted body content, special FormRequests are provided to validate \nand access request body data: `\\Czim\\JsonApi\\Http\\Requests\\JsonApiRequest`.\n\nFor `POST` requests where `id` may be omitted while creating a resource, use `\\Czim\\JsonApi\\Http\\Requests\\JsonApiRequest` instead.\n\nThese classes may be extended and used as any other FormRequest class in Laravel.\n\nThere are also a global help functions `jsonapi_request()` and `jsonapi_request_create()`, \nthat returns an instance of the relevant request class (and so mimics Laravel's `request()`).\n\nUsing this approach guarantees that requests are valid JSON-API by validating the input against a JSON Schema.\n\n```php\n\u003c?php\n    // Get the root type of the object (which may be 'resource', 'error' or 'meta').\n    $rootType = jsonapi_request()-\u003edata()-\u003egetRootType();\n    \n    // Get validated data for the current request.\n    // This returns an instance of \\Czim\\JsonApi\\Data\\Root, which is a data object tree.\n    $root = jsonapi_request()-\u003edata();\n    \n    // You can check what kind of resource data is contained.\n    if ( ! $root-\u003ehasSingleResourceData()) {\n        // In this case, the request would either have no \"data\" key,\n        // or it would contain NULL or an array of multiple resources.\n    } elseif ($root-\u003ehasMultipleResourceData()) {\n        // In this case, the request has a \"data\" key that contains an array of resources.\n    }\n    \n    // Embedded data may be accessed as follows (for single resource).\n    $resourceId     = $root-\u003edata-\u003eid;\n    $resourceType   = $root-\u003edata-\u003etype; \n    $attributeValue = $root-\u003edata-\u003eattributes-\u003ename;\n    $relationType   = $root-\u003edata-\u003erelationships['some-relationship']-\u003edata-\u003etype;\n```\n\nThe request data tree for a single-resource request:\n \n![Request Data: Single Resource](http://czim.github.io/laravel-jsonapi/images/jsonapi_data_tree_resource.png)\n\nFor more information on the data object tree, see [the Data classes](https://github.com/czim/laravel-jsonapi/tree/master/src/Data).\n\n\n### Encoding\n\nThis package offers an encoder to generate valid JSON-API output for variable input content.\n\nWith some minor setup, it is possible to generate JSON output according to JSON-API specs for Eloquent models and errors.\n\n`Eloquent` models, single, collected or paginated, will be serialized as JSON-API resources.\n \n[More information on encoding](ENCODING.md) and configuring resources.\n\n\n#### Custom Encoding \u0026 Transformation\n\nTo use your own transformers for specific class FQNs for the content to be encoded, map them in the `jsonapi.transform.map`\nconfiguration key:\n\n```php\n\u003c?php\n    'map' =\u003e [\n        \\Your\\ContentClassFqn\\Here::class =\u003e \\Your\\TransformerClassFqn\\Here::class,        \n    ],\n```\n\nThis mapping will return the first-matched for content using `is_a()` checks.\nMore specific matches should be higher in the list. \n\n\nAs a last resort, you can always extend and/or rebind the `Czim\\JsonApi\\Encoder\\Factories\\TransformerFactory` \nto provide your own transformers based on given content type.\n\n\n\n## Contributing\n\nPlease see [CONTRIBUTING](CONTRIBUTING.md) for details.\n\n\n## Credits\n\n- [Coen Zimmerman][link-author]\n- [All Contributors][link-contributors]\n\n\n## License\n\nThe MIT License (MIT). Please see [License File](LICENSE.md) for more information.\n\n[ico-version]: https://img.shields.io/packagist/v/czim/laravel-jsonapi.svg?style=flat-square\n[ico-license]: https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square\n[ico-downloads]: https://img.shields.io/packagist/dt/czim/laravel-jsonapi.svg?style=flat-square\n\n[link-packagist]: https://packagist.org/packages/czim/laravel-jsonapi\n[link-downloads]: https://packagist.org/packages/czim/laravel-jsonapi\n[link-author]: https://github.com/czim\n[link-contributors]: ../../contributors\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fczim%2Flaravel-jsonapi","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fczim%2Flaravel-jsonapi","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fczim%2Flaravel-jsonapi/lists"}