Searching Google Books with Angular

Ole Ersoy
Ole Ersoy
Nov 7 · 1 min read
Image by Free-Photos from Pixabay

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:

Related Concepts

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade