Utilisation dans un Service
bookRepository.getBookList()
.subscribe(bookList => this.bookList = bookList);Transformation de la "response" avec un opérateur
@Injectable({
providedIn: 'root'
})
export class BookRepository {
private _bookListUrl = 'https://www.googleapis.com/books/v1/volumes?q=extreme%20programming';
constructor(private _httpClient: HttpClient) {
}
getBookList() {
return this._httpClient.get<GoogleVolumeListResponse>(this._bookListUrl)
.pipe(map(googleVolumeListResponse => {
const bookList = googleVolumeListResponse.items
.map(item => new Book({
title: item.volumeInfo.title
}));
return bookList;
}));
}
}Astuce : n'oubliez pas les metadata
Mis à jour