Connecting to the Google Books API web service

In order to enable searching for books in our app, we'll connect to the Google Books API. This is an incredible web service. Its purpose is to share information about most of the books ever published, anywhere in the world. By leveraging the Google Books API service, the web app you'll build in this chapter will contain the data of millions of books.

In order to get the information we need, we have to reach the Google API through a Uniform Resource Locator (URL). This URL is made of several parts, described here:

  • The scheme: HTTPS, in this case.
  • The authority: www.googleapis.com. 
  • The path that is specific for the books API: books/v1/volumes.
  • The query string: a question mark, "q", an equals sign, and the title we are looking for—for example, ?q=flutter.

The full URL would be https://www.googleapis.com/books/v1/volumes?q=flutter.

If you put this URL in a browser, you'll see that indeed, we are connecting to the Google Books API and receiving data in the JSON format. Here, you can see a screenshot of the JSON data retrieved from the service:

As with most web services, the Google Books API takes a key to connect to the web service. To obtain a key to be added to the service, have a look at the https://developers.google.com/books/docs/v1/using#APIKey page.

When you get the API key, make sure you enable the API key for the Books API.

The data you see in the browser is what we are going to put into the first page of our web app. From the items node that contains an array of volumes, we'll only get the fields we need: the ID, the title from the volumeInfo node, the authors, and the description.

We won't get into the details of parsing JSON data here. For a refresher on connecting to a web service and using JSON, have a look at Chapter 5, Let's Go to the Movies - Getting Data from the Web.

In the next section, we'll create the model class from the parsed JSON.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.17.174.0