Search code examples
angularjsrestangular

Restangular and _links


I'm working on a AngularJS app. The app consumes a RESTful/HATEOAS API. The API has the following endpoint, amongst others:

http://localhost:8001/api/tests/1

which returns:

{
  "title": "Test",
  "description": "Test",
  "created": "2016-01-09T11:52:01+0100",
  "enabled": true,
  "is_speed_test": true,
  "test_id": 1,
  "view": [],
  "report_card": [],
  "cap": [],
  "tag": [],
  "_links": {
    "self": {
      "href": "http://localhost:8001/api/tests/2"
    },
    "module": {
      "href": "http://localhost:8001/api/subjects/2/modules/1"
    },
    "event": {
      "href": "http://localhost:8001/api/events/1"
    },
    "topics": {
      "href": "http://localhost:8001/api/subjects/2/modules/1/topics"
    },
    "creatorUser": {
      "href": "http://localhost:8001/api/users/admin"
    }
  }
}

How can I use Restangular to get a linked module, event, topics, etc. ?


Solution

  • This is what I used to get it to work.

    Restangular.oneUrl('module', test._link.module.href);