Skip to main content
Code Review

Return to Question

Notice removed Draw attention by Community Bot
Bounty Ended with Sᴀᴍ Onᴇᴌᴀ's answer chosen by Community Bot
Update wording
Source Link

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?

edited tags
Link
Notice added Draw attention by Matt W
Bounty Started worth 50 reputation by Matt W
edited tags
Link
200_success
  • 145.5k
  • 22
  • 190
  • 478
Source Link
Matt W
  • 157
  • 1
  • 10
Loading
lang-js

AltStyle によって変換されたページ (->オリジナル) /