I have an Angular service consisting of three methods:
This method makes a call to my server to get a URL
private itemUrl = "http://fooserver/api/get/item/details"; getItemDetailsUrl(productId): Observable<any> { return this.http .get(this.itemUrl, { params: { productId: productId } }) .flatMap(res => this.getItemDetails(res.json().itemUrl)) .map(item => item); }
This takes that URL from #1 and grabs the XML data returned from the request and passes it to #3
getItemDetails(url): Observable<any> { return this.http .get(url) .flatMap(item => this.parseItemFromUrl(item)); }
The XML passed is then converted to a JSON object using a third party library and then returned:
parseItemFromUrl(xml): any { let item; xml2js.parseString(xml.text(), function (err, result) { item = result.ItemLookupResponse.Items[0].Item[0]; }); return Observable.of(item); }
This code does return the expected JSON object back. But since this is my first time really using Observables, I'd like to know of any improvements or changes I could make and if I used the appropriate array methods in the appropriate places.