I am fairly new to angular and am still trying to wrap my head around doing things the angular + httpClient + rxjs way. I am trying to write the rxjs equivalent of the following:
async onButtonClick = () => {
const processedBooks = await this.getAndProcessBooks();
await myGenericHttpClient.post('/api/something', processedBooks);
}
async getAndProcessBooks = () => {
const books = await myGenericHttpClient.get('/api/books');
const processedBooks = books.map(book => {
return book.read = true;
});
return books;
};
My understanding of rxjs is i need to use angular's httpClient to make the request then subscribe to the response:
getAndProcessBooks = () => {
return httpClient.get('/api/books').subscribe(books => {
return books;
});
};
However, the problem is getAndProcessBooks returns a subscription, not an array of books so I'm not sure how this method can return the data that I need. Any help or direction to resources would be appreciated!