Every time I think I understand Observables, I don't quite understand Observables. So consider this code I use in my Angular 4 app:
// this returns the url to our bitbucket server. the uriService returns
// an Observable<string>
return this.uriService.getBitBucketUrl(path)
// I expect exactly one result, no more, no less, otherwise exception
.single()
// somehow I still need a flatMap here, to supply the url value into the nested observable
.flatMap((url: string) => {
// we now have the bitbucket url, use it to get json from it.
return this.httpService.getJson(url)
// map the result and flatten it to an array
.flatMap((json: HttpResponse<any>): Array<any> => json.body.values)
// map each value into a more managed model
.map<any, BitbucketModel>((value: any) => {
// create and return BitBucketModel here based on json
})
});
I hope I explain the code well enough, so the essence of it is that I don't want to use 'subscribe' anywhere. because I use the async pipe I want observables all the way down. But when I use single() and then I have to flatMap it otherwise it gives me an error because I can't return Observable < Observable < BitBucketModel > >.
EDIT I'm sorry if I didn't make it clear enough what I was asking. My scenario is that I basically need a config setting where my actual http request is based on. So I must retrieve that setting and based on that settings do that actual http request.