I need to do a query to 2 separate endpoints to provide the objects needed for my component.
| No | Endpoint | Response |
|---|---|---|
| 1 | /registry/colors |
{"colors":["red","green","blue","orange"]} |
| 2 | /color/{colorName} |
{"name":"red", "details":["detail1","detail2", "detail3"]} |
For each color in the colors array, I need to call the color details endpoint and collect all of those color details into an array of Colors.
getColors(): Observable<Color[]> {
return this.http.get<ColorRegistry>(this.registryUrl).pipe(
map((registry:ColorRegistry) => registry.colors.concatMap((colorName: string) => {
return this.http.get<Color>(this.colorUrl+"/"+colorName);
}))
)
}
I would like the above method to return the following:
[
{"name":"red", "details":["detail1","detail2", "detail3"]},
{"name":"green", "details":["detail1","detail2", "detail3"]},
{"name":"blue", "details":["detail1","detail2", "detail3"]},
{"name":"orange", "details":["detail1","detail2", "detail3"]}
]
Obviously I'm going about this the wrong way, I'm looking for the correct way to do the nested requests with observables.