'How to get data for _links in nextjs external api call
I am calling an api in my nestjs application. The response of api has hateoas format like below
and here is my code
import { HttpService, Injectable } from '@nestjs/common';
import { Observable } from 'rxjs';
import { catchError, map, switchMap, tap } from 'rxjs/operators';
@Injectable()
export class IqProductQuantityService {
constructor(
private readonly httpService: HttpService
) {}
...
return this.httpService
.get<any>(url, {
headers: {
Authorization: `Bearer ${token}`
}
})
.pipe(
map((res) => res.data),
tap((data) => console.log(data)),
tap((data) => console.log(data?._links?._next))
);
The problem is when I get data, I receive Array of items, and there is no _links or _embeded data in the response, seems the axios or nestjs is parsing this data gracefuly to make the life easier, but at same time we lost the information of _links.next to do paging
This is what I receive:
console.log(data):
[
{
Id: '82cf8651-c742-4352-aa70-001ee180707c',
CompanyId: 13279,
EntityId: 22235,
IsSerialized: false,
IsDropShippable: false,
IsLot: false,
QuantityInStock: 0,
QuantityOnOrder: 0,
QuantityTransferIn: 0,
QuantityTransferOut: 0,
UnitId: 0
},
{
Id: '82cf8651-c742-4352-aa70-001ee180707c',
CompanyId: 13279,
EntityId: 22236,
IsSerialized: false,
IsDropShippable: false,
IsLot: false,
QuantityInStock: 0,
QuantityOnOrder: 0,
QuantityTransferIn: 0,
QuantityTransferOut: 0,
UnitId: 0
},
{
Id: '82cf8651-c742-4352-aa70-001ee180707c',
CompanyId: 13279,
EntityId: 22237,
IsSerialized: false,
IsDropShippable: false,
IsLot: false,
QuantityInStock: 0,
QuantityOnOrder: 0,
QuantityTransferIn: 0,
QuantityTransferOut: 0,
UnitId: 0
}
]
console.log(data?._links?._next):
undefined
The question is how should I retrieve _links.next.href data?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|

