
Scenario
We want to search the Google Book API using Angular.
Approach
Build a search service:
private API = 'https://www.googleapis.com/books/v1/volumes';constructor(private http: HttpClient) {}
search(query: string): Observable<Book[]> {
return this.http
.get<{ items: Book[] }>(`${this.API}?q=${query}`)
.pipe(map(books => books.items || []));
}getById(volumeId: string): Observable<Book> {
return this.http.get<Book>(`${this.API}/${volumeId}`);
}
Demo
Try searching for Angular and look in the console for the results:
