{"id":20081568,"url":"https://github.com/mixerapi/json-ld-view","last_synced_at":"2026-02-16T14:31:23.712Z","repository":{"id":49094543,"uuid":"293183999","full_name":"mixerapi/json-ld-view","owner":"mixerapi","description":"A JSON-LD view for CakePHP [READ-ONLY]","archived":false,"fork":false,"pushed_at":"2026-02-15T17:37:21.000Z","size":59,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2026-02-16T00:15:45.798Z","etag":null,"topics":["cakephp","hateoas","json-ld","jsonld","php"],"latest_commit_sha":null,"homepage":"https://mixerapi.com/plugins/json-ld-view","language":"PHP","has_issues":false,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mixerapi.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"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,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2020-09-06T01:46:45.000Z","updated_at":"2026-02-15T17:37:24.000Z","dependencies_parsed_at":"2025-01-13T01:41:13.123Z","dependency_job_id":"dcf077f5-1a68-47e3-96c0-5f3b2d575113","html_url":"https://github.com/mixerapi/json-ld-view","commit_stats":{"total_commits":15,"total_committers":1,"mean_commits":15.0,"dds":0.0,"last_synced_commit":"084a770df91b9a6df8b9c7f9d4ead53dcd6fb1ed"},"previous_names":[],"tags_count":24,"template":false,"template_full_name":null,"purl":"pkg:github/mixerapi/json-ld-view","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mixerapi%2Fjson-ld-view","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mixerapi%2Fjson-ld-view/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mixerapi%2Fjson-ld-view/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mixerapi%2Fjson-ld-view/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mixerapi","download_url":"https://codeload.github.com/mixerapi/json-ld-view/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mixerapi%2Fjson-ld-view/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29510137,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-16T09:05:14.864Z","status":"ssl_error","status_checked_at":"2026-02-16T08:55:59.364Z","response_time":115,"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":["cakephp","hateoas","json-ld","jsonld","php"],"created_at":"2024-11-13T15:39:30.020Z","updated_at":"2026-02-16T14:31:23.696Z","avatar_url":"https://github.com/mixerapi.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# MixerAPI JsonLdView\n\n[![Latest Version on Packagist](https://img.shields.io/packagist/v/mixerapi/json-ld-view.svg?style=flat-square)](https://packagist.org/packages/mixerapi/json-ld-view)\n[![Build](https://github.com/mixerapi/json-ld-view/workflows/Build/badge.svg?branch=master)](https://github.com/mixerapi/mixerapi-dev/actions?query=workflow%3ABuild)\n[![Coverage Status](https://coveralls.io/repos/github/mixerapi/json-ld-view/badge.svg?branch=master)](https://coveralls.io/github/mixerapi/json-ld-view?branch=master)\n[![MixerApi](https://mixerapi.com/assets/img/mixer-api-red.svg)](https://mixerapi.com)\n[![CakePHP](https://img.shields.io/badge/cakephp-^4.2-red?logo=cakephp)](https://book.cakephp.org/4/en/index.html)\n[![Minimum PHP Version](https://img.shields.io/badge/php-^8.0-8892BF.svg?logo=php)](https://php.net/)\n\nA [JSON-LD](https://json-ld.org/) View for CakePHP. Read more at [MixerAPI.com](https://mixerapi.com).\n\n## Installation\n\n!!! info \"\"\n    You can skip this step if MixerAPI is installed.\n\n```console\ncomposer require mixerapi/json-ld-view\nbin/cake plugin load MixerApi/JsonLdView\n```\n\nAlternatively after composer installing you can manually load the plugin in your Application:\n\n```php\n# src/Application.php\npublic function bootstrap(): void\n{\n    // other logic...\n    $this-\u003eaddPlugin('MixerApi/JsonLdView');\n}\n```\n\n## Setup\n\nSetup for this plugin is very easy. Just load the RequestHandler component and create a route for contexts and\nvocab. Then create a `config/jsonld_config.php` config file (recommended) and implement JsonLdDataInterface on your\nentities.\n\n#### Config (recommended)\n\nCreate a [config/jsonld_config](assets/jsonld_config.php). If you skip this step then the defaults listed in the\nsample config will be used.\n\n#### RequestHandler\n\nYour controllers must be using the `RequestHandler` component. This is typically loaded in your `AppController`. In\nmost cases this is already loaded.\n\n```php\n# src/Controller/AppController.php\npublic function initialize(): void\n{\n    parent::initialize();\n    $this-\u003eloadComponent('RequestHandler');\n    // other logic...\n}\n```\n\n#### Routes\n\nThe contexts route displays your JSON-LD schema for an entity, while the vocab route will display all entities and\nadditional metadata.\n\n```php\n# config/routes.php\n$routes-\u003escope('/', function (RouteBuilder $builder) {\n    $builder-\u003econnect('/contexts/*', [\n        'plugin' =\u003e 'MixerApi/JsonLdView', 'controller' =\u003e 'JsonLd', 'action' =\u003e 'contexts'\n    ]);\n    $builder-\u003econnect('/vocab', [\n        'plugin' =\u003e 'MixerApi/JsonLdView', 'controller' =\u003e 'JsonLd', 'action' =\u003e 'vocab'\n    ]);\n    // ... other code\n});\n```\n\nYou should now be able see entities JSON-LD schema by browsing to `/contexts/{entity-name}`. For further customization\nyou can copy the JsonLdController into your own project.\n\n#### Route Extension (optional)\n\nIf you would like to request JSON-LD by extension (e.g. `/index.jsonld`) you'll need to set the extension in your\n`config/routes.php`, example:\n\n```php\n# config/routes.php\n$routes-\u003escope('/', function (RouteBuilder $builder) {\n    $builder-\u003esetExtensions(['jsonld']);\n    // ... other code\n});\n```\n\n## Usage\n\nOnce setup is complete request types of `application/ld+json` will automatically be rendered as JSON-LD.\n\n### Entity Schema\n\nThis plugin will map basic types (int, string, decimal etc.) to their corresponding schema.org values. For instance,\n`int` is mapped to `https://schema.org/Number`. You can improve the mappings by defining proper Validations on your\nTable class. For instance, fields with the `email` rule will be mapped to `https://schema.org/email`. For a full list\nof default mappings refer to `MixerApi\\JsonLdView\\SchemaMapper`.\n\nYou can further customize the schema mapping by implementing `MixerApi\\JsonLdView\\JsonLdDataInterface` on your\napplications Entities:\n\n```php\n# App/Model/Entity/Film.php\nclass Film extends Entity implements JsonLdDataInterface\n{\n    // ...other code\n\n    /**\n     * This is the context URL that you defined in your routes during Setup. This is used to browse the schema\n     * definitions and appears as `@context` when displaying collection or item results\n     *\n     * @return string\n     */\n    public function getJsonLdContext(): string\n    {\n        return '/contexts/Film';\n    }\n\n    /**\n     * This is the Entities schema description and appears as `@type` when displaying collection or item results\n     *\n     * @return string\n     */\n    public function getJsonLdType(): string\n    {\n        return 'https://schema.org/movie';\n    }\n\n    /**\n     * This is the Entities URL and appears as `@id` when displaying collection or item results\n     *\n     * @param EntityInterface $entity\n     * @return string\n     */\n    public function getJsonLdIdentifier(EntityInterface $entity): string\n    {\n        return '/films/' . $entity-\u003eget('id');\n    }\n\n    /**\n     * You can define custom schemas here. These definitions take precedence and will appear when browsing to the\n     * entities context URL. You can simply return an empty array if you don't care to define a schema.\n     *\n     * @return \\MixerApi\\JsonLdView\\JsonLdSchema[]\n     */\n    public function getJsonLdSchemas(): array\n    {\n        return [\n            new JsonLdSchema('title','https://schema.org/name', 'optional description')\n            new JsonLdSchema('description','https://schema.org/about')\n            new JsonLdSchema('length','https://schema.org/duration')\n            new JsonLdSchema('rating','https://schema.org/contentRating')\n            new JsonLdSchema('release_year','https://schema.org/copyrightYear')\n        ];\n    }\n}\n```\n\n### Collections\n\nWe get the `@id` and `@context` properties because these Entities implement `JsonLdDataInterface`. This interface is\nof course optional and data will return without it minus the aforementioned properties. Pagination data is added in\nthe `view` property per the Hydra [PartialCollectionView](https://www.w3.org/community/hydra/wiki/Pagination)\n specification.\n\n```php\n#src/Controller/FilmsController.php\npublic function index()\n{\n    $this-\u003erequest-\u003eallowMethod('get');\n    $actors = $this-\u003epaginate($this-\u003eFilms, [\n        'contain' =\u003e ['Languages'],\n    ]);\n    $this-\u003eset(compact('films'));\n    $this-\u003eviewBuilder()-\u003esetOption('serialize', 'films');\n}\n```\n\n\u003cdetails\u003e\u003csummary\u003eExample:\u003c/summary\u003e\n  \u003cp\u003e\n\n```json\n{\n  \"@context\": \"/context/Film\",\n  \"@id\": \"/films\",\n  \"@type\": \"Collection\",\n  \"pageItems\": 20,\n  \"totalItems\": 1,\n  \"view\": {\n    \"@id\": \"/films\",\n    \"@type\": \"PartialCollectionView\",\n    \"next\": \"/films?page=2\",\n    \"prev\": \"\",\n    \"first\": \"\",\n    \"last\": \"/films?page=50\"\n  },\n  \"member\": [\n    {\n      \"id\": 1,\n      \"title\": \"ACADEMY DINOSAUR\",\n      \"description\": \"A Epic Drama of a Feminist And a Mad Scientist who must Battle a Teacher in The Canadian Rockies\",\n      \"modified\": \"2006-02-15T05:03:42+00:00\",\n      \"language\": {\n        \"id\": 1,\n        \"name\": \"English\",\n        \"@id\": \"/languages/1\",\n        \"@type\": \"https://schema.org/Language\",\n        \"@context\": \"/context/Language\"\n      },\n      \"@id\": \"/films/1\",\n      \"@type\": \"https://schema.org/Movie\",\n      \"@context\": \"/context/Film\"\n    }\n  ]\n}\n```\n\u003c/p\u003e\n\u003c/details\u003e\n\n### Items\n\n```php\n#src/Controller/LanguagesController.php\npublic function view($id = null)\n{\n    $this-\u003erequest-\u003eallowMethod('get');\n    $languages = $this-\u003eLanguages-\u003eget($id);\n    $this-\u003eset('languages', $languages);\n    $this-\u003eviewBuilder()-\u003esetOption('serialize', 'languages');\n}\n```\n\nOutput:\n\n```json\n{\n  \"@id\": \"/languages/1\",\n  \"@type\": \"https://schema.org/Language\",\n  \"@context\": \"/context/Language\",\n  \"id\": 1,\n  \"name\": \"English\"\n}\n```\n\n### Contexts\n\nBrowsing to the contexts route will display information about that entity. To fine tune to the data you will need to\nimplement JsonLdDataInterface. Using the Film entity as an example, the context looks like this when browsing to\n`/contexts/Film`:\n\n```json\n{\n  \"@context\": {\n    \"@vocab\": \"/vocab\",\n    \"hydra\": \"http://www.w3.org/ns/hydra/core#\",\n    \"title\": \"https://schema.org/name\",\n    \"description\": \"https://schema.org/about\",\n    \"length\": \"https://schema.org/duration\",\n    \"rating\": \"https://schema.org/contentRating\",\n    \"release_year\": \"https://schema.org/copyrightYear\",\n    \"id\": \"https://schema.org/identifier\",\n    \"language_id\": \"https://schema.org/Number\",\n    \"rental_duration\": \"https://schema.org/Number\",\n    \"rental_rate\": \"https://schema.org/Float\",\n    \"replacement_cost\": \"https://schema.org/Float\",\n    \"special_features\": \"https://schema.org/Text\",\n    \"modified\": \"https://schema.org/DateTime\"\n  }\n}\n```\n\n#### Vocab\n\nAny entities implementing the JsonLdDataInterface will appear when browsing to the route you created for vocab\n(e.g. /vocab):\n\n\u003cdetails\u003e\u003csummary\u003eSample:\u003c/summary\u003e\n  \u003cp\u003e\n\n```json\n\n{\n    \"@contexts\": {\n        \"@vocab\": \"/vocab\",\n        \"rdf\": \"http://www.w3.org/1999/02/22-rdf-syntax-ns#\",\n        \"rdfs\": \"http://www.w3.org/2000/01/rdf-schema#\",\n        \"xmls\": \"http://www.w3.org/2001/XMLSchema#\",\n        \"owl\": \"http://www.w3.org/2002/07/owl#\",\n        \"schema\": \"http://schema.org\"\n    },\n    \"@id\": \"/vocab\",\n    \"@type\": \"ApiDocumentation\",\n    \"title\": \"API Documentation\",\n    \"description\": \"\",\n    \"supportedClass\": [\n        {\n            \"@id\": \"https://schema.org/Language\",\n            \"@type\": \"Class\",\n            \"title\": \"Language\",\n            \"supportedProperty\": [\n                {\n                    \"@type\": \"supportedProperty\",\n                    \"property\": {\n                        \"@id\": \"https://schema.org/name\",\n                        \"@type\": \"rdf:Property\",\n                        \"rdfs:label\": \"name\",\n                        \"domain\": \"https://schema.org/Language\",\n                        \"range\": \"xmls:char\"\n                    },\n                    \"title\": \"name\",\n                    \"required\": false,\n                    \"readable\": true,\n                    \"writeable\": true,\n                    \"description\": \"\"\n                }\n            ]\n        }\n        // ...and other items\n    ]\n}\n```\n\u003c/p\u003e\n\u003c/details\u003e\n\n### Serializing\n\nOptionally, you can manually serialize data into JSON-LD using `JsonSerializer`. Example:\n\n```php\nuse MixerApi\\JsonLdView\\JsonSerializer;\n\n# json\n$json = (new JsonSerializer($data))-\u003easJson(JSON_PRETTY_PRINT); // argument is optional\n\n# array\n$json = (new JsonSerializer($data))-\u003egetData();\n\n# json-ld with pagination meta data\nuse Cake\\Http\\ServerRequest;\nuse Cake\\View\\Helper\\PaginatorHelper;\n$json = (new JsonSerializer($data, new ServerRequest(), new PaginatorHelper()))-\u003easJson();\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmixerapi%2Fjson-ld-view","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmixerapi%2Fjson-ld-view","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmixerapi%2Fjson-ld-view/lists"}