I would like to know if this is the best/most efficient/industry standard way of converting from the http
response to an array of typed values:
Type class:
export class University {
public "state-province": string;
public country: string;
public name: string;
constructor(state_province: string, country: string, name: string) {
this["state-province"] = state_province;
this.country = country;
this.name = name;
}
}
Here is the http
request and conversion - the. The code in question is within the map(...)
call:
const resp = this.http
.get<University[]>(`http://universities.hipolabs.com/search?country=United+Kingdom&name=camb`)
.pipe(map(respData => {
const uniArr: University[] = [];
respData.forEach(element => {
uniArr.push(new University(element['state-province'], element.country, element.name));
});
return uniArr;
}))
.subscribe(respData => {
console.log('Content:', respData);
});
In C#
there are many easier ways to convert the response data of the get
request into an array (or list) of typed instances. Am I doing this correctly here, in Angular/RxJS?
I would like to know if this is the best/most efficient/industry standard way of converting from the http
response to an array of typed values:
Type class:
export class University {
public "state-province": string;
public country: string;
public name: string;
constructor(state_province: string, country: string, name: string) {
this["state-province"] = state_province;
this.country = country;
this.name = name;
}
}
http
request and conversion - the code in question is within the map(...)
call:
const resp = this.http
.get<University[]>(`http://universities.hipolabs.com/search?country=United+Kingdom&name=camb`)
.pipe(map(respData => {
const uniArr: University[] = [];
respData.forEach(element => {
uniArr.push(new University(element['state-province'], element.country, element.name));
});
return uniArr;
}))
.subscribe(respData => {
console.log('Content:', respData);
});
In C#
there are many easier ways to convert the response data of the get
request into an array (or list) of typed instances. Am I doing this correctly here, in Angular/RxJS?
I would like to know if this is the best/most efficient/industry standard way of converting from the http
response to an array of typed values:
Type class:
export class University {
public "state-province": string;
public country: string;
public name: string;
constructor(state_province: string, country: string, name: string) {
this["state-province"] = state_province;
this.country = country;
this.name = name;
}
}
Here is the http
request and conversion. The code in question is within the map(...)
call:
const resp = this.http
.get<University[]>(`http://universities.hipolabs.com/search?country=United+Kingdom&name=camb`)
.pipe(map(respData => {
const uniArr: University[] = [];
respData.forEach(element => {
uniArr.push(new University(element['state-province'], element.country, element.name));
});
return uniArr;
}))
.subscribe(respData => {
console.log('Content:', respData);
});
In C#
there are many easier ways to convert the response data of the get
request into an array (or list) of typed instances. Am I doing this correctly here, in Angular/RxJS?