title: How to get my resource data from a HAL response?
body: <p>I'm building an API using Spring Boot 2 and the Angular 6 client has to deal with responses such as this one for example :</p>
  
  <pre><code>{
    "_embedded" : {
      "userResourceList" : [ {
        "firstname" : "Stephane",
        "lastname" : "Toto",
        "email" : "toto@yahoo.se",
        "confirmedEmail" : false,
        "password" : "bWl0dGlwcm92ZW5jZUB5YWhvby5zZTptaWduZXRjNWRlMDJkZS1iMzIwLTQ4Y2YtOGYyMS0wMmFkZTQ=",
        "userRoles" : [ {
          "role" : "ROLE_ADMIN",
          "id" : 1
        } ],
        "_links" : {
          "self" : {
            "href" : "http://localhost:8080/api/users/1"
          },
          "roles" : {
            "href" : "http://localhost:8080/api/users/1/roles"
          }
        },
        "id" : 1
      } ]
    },
    "_links" : {
      "self" : {
        "href" : "http://localhost:8080/api/users"
      }
    },
    "page" : {
      "size" : 20,
      "totalElements" : 1,
      "totalPages" : 1,
      "number" : 0
    }
  }
  </code></pre>
  
  <p>All REST resources endpoints would retrun such HALified responses.</p>
  
  <p>I wonder how to deal with these. If there is such library that eases the parsing and extraction of the actual payload.</p>
  
  <p>I heard of the <a href="https://ngx-restangular.com/" rel="nofollow noreferrer">RestAngular</a> library but I'm not so sure it's what I want.</p>
  
  <p>Maybe something less invasive only assisting in the parsing like :</p>
  
  <pre><code>const user: User = hal2Json.parse&lt;User&gt;(response);
  </code></pre>
  
  <p>UPDATE: I didn't find any such library and so I resorted to this implementation:</p>
  
  <pre><code>public getSome(searchTerm: string, sortFieldName: string, sortDirection: string, currentPage: number, limit: number): Observable&lt;any&gt; {
    let httpParams = new HttpParams()
    .set('page', currentPage.toString())
    .set('size', limit.toString());
    if (searchTerm) {
      httpParams = httpParams.append('searchTerm', searchTerm);
    }
    if (sortFieldName &amp;&amp; sortDirection) {
      httpParams = httpParams.append('sort', sortFieldName + ',' + sortDirection);
    }
    return this.httpService.get(this.usersUrl, httpParams);
  }
  
  export class UsersApi extends PaginationApi {
  
    constructor(users: User[], currentPageNumber: number, elementsPerPage: number, totalElements: number, totalPages: number) {
        super(currentPageNumber, elementsPerPage, totalElements, totalPages);
        this.users = users;
    }
  
    users: User[];
  
  }
  
  getUsers(searchTerm: string, sortFieldName: string, sortDirection: string, currentPageNumber: number): Observable&lt;UsersApi&gt; {
    return this.userService.getSome(searchTerm, sortFieldName, sortDirection, currentPageNumber, this.elementsPerPage)
      .pipe(
        map(response =&gt; {
          return new UsersApi(
            response._embedded.userResourceList as User[],
            this.paginationService.correctPageNumberMispatch(response.page.number),
            response.page.size,
            response.page.totalElements,
            response.page.totalPages
          );
        })
      );
  }
  </code></pre>