I have a function that fetches information from a REST API in this format:
getProducts(category: string): Observable<IProduct[]> {
let url = `/rest/getproducts?category=${category}`;
return this._http.get<IProduct[]>(url);
}
The data returned by the service is structured like below:
[
{
"ProductId": 1,
"CategoryType": "XC",
"Name": "Prod A"
},
{
"ProductId": 2,
"CategoryType": "XY",
"Name": "Prod B"
},
]
This is how my model is defined:
export interface IProduct {
id: string;
type: string;
name: string;
}
Is there an easy way to map the response from the service to fit my model structure? Should I use the map function for this task? While I can adjust the model to match the response, I prefer to find a way to adapt the response to fit my existing model (the example provided has been simplified).