Search code examples
restapirestful-architectureapi-designhateoas

What should i do with links returned after calling REST API?


I am building front end for a project. I am using Angular2 for the front end. The API i must call is RESTful. It implements HATEOAS. When i call an API it gives me data and links. These links are from HATEOAS. When i call the API should i save the data as well as HATEOAS links in a model or just the data. For example: the API call: localhost:/api/users/ gives me following response:

{
 "id":"105",
 "name": "John"
 "salary": "10000",
 "links": {
         "getSalary": {
         "method": "GET",
         "url": "/api/users/105/salary",
         "headers": [
           "X-Auth-Token",
           "Content-Type"
          ],
         "body": null
}

So what do i do with the links part? Should i save the links in the model at front end or just the relevant data like id, name, salary, etc? The links part will have other links also explaining POST, PUT, DELETE, etc links.


Solution

  • Should i save the links in the model at front end

    You should not save the URL to your data model on the front end. Either:

    1. use the URL to get more data that you need; or
    2. throw it away if you don't need it