{"id":13804669,"url":"https://github.com/201-created/ember-data-hal-9000","last_synced_at":"2025-05-13T17:32:47.882Z","repository":{"id":23464920,"uuid":"26829113","full_name":"201-created/ember-data-hal-9000","owner":"201-created","description":"An ember-data compatible ember-cli addon that provides a HAL adapter","archived":false,"fork":false,"pushed_at":"2024-04-16T06:21:12.000Z","size":103,"stargazers_count":38,"open_issues_count":20,"forks_count":23,"subscribers_count":9,"default_branch":"master","last_synced_at":"2025-04-09T18:58:09.429Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://github.com/201-created/ember-data-hal-9000","language":"JavaScript","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/201-created.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.md","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}},"created_at":"2014-11-18T20:44:11.000Z","updated_at":"2020-01-23T14:58:12.000Z","dependencies_parsed_at":"2024-06-20T00:22:55.363Z","dependency_job_id":null,"html_url":"https://github.com/201-created/ember-data-hal-9000","commit_stats":{"total_commits":70,"total_committers":8,"mean_commits":8.75,"dds":"0.18571428571428572","last_synced_commit":"10ffdb8807bdab17a7470f9301ce4d7bda4a2847"},"previous_names":[],"tags_count":16,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/201-created%2Fember-data-hal-9000","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/201-created%2Fember-data-hal-9000/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/201-created%2Fember-data-hal-9000/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/201-created%2Fember-data-hal-9000/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/201-created","download_url":"https://codeload.github.com/201-created/ember-data-hal-9000/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253481087,"owners_count":21915261,"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":[],"created_at":"2024-08-04T01:00:52.303Z","updated_at":"2025-05-13T17:32:47.509Z","avatar_url":"https://github.com/201-created.png","language":"JavaScript","funding_links":[],"categories":["Packages"],"sub_categories":["Adapters"],"readme":"# Ember-data-hal-9000\n\nAn ember-data adapter for HAL-style APIs.\n\nSee the [IETF HAL Spec](https://tools.ietf.org/html/draft-kelly-json-hal-06) or [this HAL document](http://stateless.co/hal_specification.html) for more info on HAL.\n\n[![Build\nStatus](https://travis-ci.org/201-created/ember-data-hal-9000.svg?branch=master)](https://travis-ci.org/201-created/ember-data-hal-9000)\n[![Code Climate](https://codeclimate.com/github/201-created/ember-data-hal-9000/badges/gpa.svg)](https://codeclimate.com/github/201-created/ember-data-hal-9000)\n[![Ember Observer Score](http://emberobserver.com/badges/ember-data-hal-9000.svg)](http://emberobserver.com/addons/ember-data-hal-9000)\n\n## Compatibility\n\nember-data-hal-9000 supports ember data pre beta 19, beta 19, and ember data 1.13 support is coming soon.\n\nEmber Data \u003c 1.0.0-beta.19 | Ember Data 1.0.0-beta.19.2 | Ember Data 1.13.8+, 2.0.0-beta.1+\n---------------------------|----------------------------|----------------\nuse 0.1.x  | use 0.2.x  | use 0.3.x\n\n## Usage\n\nInstall `ember-data-hal-9000`:\n\n * `npm install --save-dev ember-data-hal-9000`\n * Extend your application adapter from the HAL-9000 adapter, e.g.:\n\n```javascript\n// app/adapters/application.js\n\nimport HalAdapter from \"ember-data-hal-9000/adapter\";\nexport default HalAdapter.extend();\n```\n\n * Extend your application serializer from the HAL-9000 serializer, e.g.:\n\n```javascript\n// app/serializers/application.js\n\nimport HalSerializer from \"ember-data-hal-9000/serializer\";\nexport default HalSerializer.extend();\n```\n\nTested with [Ember Data versions 1.13.4, 1.13.9, 2.0.0-beta.1 and 2.0.0-beta.2](https://github.com/201-created/ember-data-hal-9000/blob/master/config/ember-try.js).\nTested with Ember release, beta and canary channels.\n\n### HAL Links converted to JSONAPI links\n\nHAL [link objects](https://tools.ietf.org/html/draft-kelly-json-hal-06#section-5) get converted to [JSONAPI document links](http://jsonapi.org/format/#document-links) as of v0.3.1 (via @makepanic).\n\n### Sideloading\n\nHAL specifies that the API should return `_embedded` values for\nassociations. The HAL serializer will restructure incoming JSON payloads\nto turn these back into the format that ember-data expects for\nsideloads. It will restructure arbitrarily deeply nested embeds, and it\nwill delete `_links` keys when they match embedded properties. Example:\n\n```javascript\n// GET /users/1\n{\n  id: 1,\n  name: 'the user',\n  _links: {\n    self: { href: '/users/1' },\n    pet:  { href: '/users/1/pet' }\n  },\n  _embedded: {\n    pet: {\n      id: 'pet-2',\n      name: 'fido'\n    }\n  }\n}\n\n// The HAL serializer will restructure this JSON like so:\n{\n  user: {\n    id: 1,\n    name: 'the user',\n    pet: 'pet-2'      // \u003c-- adds the 'pet' property to user, using the pet id value\n  },\n  pets: [{\n    id: 'pet-2',\n    name: 'fido'\n  }],\n  links: {\n    self: '/users/1'\n    //  \u003c-- note 'pet' link is deleted since the user's pet was embedded\n  }\n}\n\n// This code in your route will work.\nstore.get('user', 1).then(function(user){\n  return user.get('pet'); // ember-data will use the sideloaded pet and will not GET /users/1/pet\n});\n```\n\n### Meta data\n\nThe HAL spec mentions that information about a collection resource can\nbe included in the root of the JSON payload, alongside the required\n`_embedded` key.\n\nThe HAL adapter will read all non-reserved property names (i.e., those other\nthan `_embedded` and `_links`) and set them as meta data. For example:\n\n```javascript\n// Assuming GET /users returns this:\n{\n  _embedded: {\n    users: [{...}, ...]\n  },\n  current_page: 1\n}\n\n// Using this code in your route will work:\nstore.find('user').then(function(){\n  console.log( store.metadataFor('user').current_page ); // 1\n});\n```\n\nNote that this *only works for collection resources*. Singular\nresources, according to the HAL spec, have all their properties in the\nroot of the payload so it is not possible to know which are intended to\nbe meta data.\n\nFor this reason, if your API response includes a `meta` key (for\nsingular or collection requests), the values in the meta will be set.\nExample:\n\n```javascript\n// Assuming GET /users/1 returns this:\n{\n  id: 1,\n  name: 'the user',\n  meta: {\n    my_meta_val: true\n  }\n}\n\n// Using this code in your route will work:\nstore.find('user', 1).then(function(){\n  console.log( store.metadataFor('user').my_meta_val ); // true\n});\n```\n\nIn addition, *for collection resources only*, the links will be set on\nthe meta data as well. Example:\n\n```javascript\n// Assuming GET /users returns this:\n{\n  _embedded: { users: [{...}, ...] },\n  _links: {\n    self: '/users',\n    next: '/users?page=2'\n  }\n}\n\n// Using this code in your route will work:\nstore.find('user').then(function(){\n  console.log( store.metadataFor('user').links.next ); // '/users?page=2'\n});\n```\n\nLinks for a singular resource will be available on the 'data' property,\ni.e.:\n\n```javascript\nstore.get('user', 1).then(function(user){\n  console.log( user.get('data.links') ); // {self: '/users/1', ... }\n});\n```\n\nNote that when a singular resource response includes an embedded\nresource, the HAL adapter will sideload that embedded resource and\n*delete* the link for that resource, if there is one (otherwise\nember-data will eagerly follow the link when you `get` the associated\nresource). See the example above in the section on sideloading.\n\n## Running Tests\n\n* `npm test` # test all scenarios in config/ember-try.js\n* `ember try \u003cscenario-name\u003e test --server` # test a specific scenario\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F201-created%2Fember-data-hal-9000","html_url":"https://awesome.ecosyste.ms/projects/github.com%2F201-created%2Fember-data-hal-9000","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F201-created%2Fember-data-hal-9000/lists"}