Keep Your Library Up-to-Date with Google Books API



Books are fundamental elements of our culture. No matter where you live or what your cultural background, we are sure that there has been at least one book that impacted your life and left great memories.

Like with most things, the technology to create books has drastically evolved from the stone tablet, to the Gutenberg press and to the on-demand printing of the laser printer. Today’s technology has brought us e-books. At the time of this article’s writing, e-books sales are surpassing the sales of traditional paperback books. E-book readers are incredible devices, capable of storing thousands of books in an 8-ounce package. E-Books are not only easy to consume but incredibly easy to publish, using an online publishing platform like Amazon, Lulu, Blurb, etc.



Because the content of books is so important to humankind in many ways, we invest significant amounts of time and money to help them stand the test of time, and of course, we organize them so we can quickly find a particular title or author when needed.

In addition to public libraries and museums, books can also be found in places very close to us such as schools, churches and local bookshops. All of these locations share a common problem: how to keep their local catalogs up-to-date in a dynamically changing environment.

In the following example we will show how to retrieve up-to-date book information using technologies like XQuery, JSON and Web Service along with just one single tool, the Stylus Studio XML IDE.

Let’s start with a list of books which has been maintained manually, using the most outdated content editor, Notepad.

What we have here is just a list of book titles in a text file. Time to hit the keyboard and write some code.

First, we need to find an entity which stores information about all published books and exposes this information as a service so we can run some queries.

The Google Books web platform fits the bill; it’s very easy to sign up and obtain an API key which can be used to run up to 1000 queries per day into their book repository using a simple REST/JSON API. Learn more at https://developers.google.com/books/docs/v1/getting_started

Here is a simple example executed in the browser in which we look up the famous children’s book entitled Pinocchio. We can clearly see how the Google Books service returns the data using JSON format, the list of attributes is quite long: title, author, format, number of pages, ISBN, publisher, etc.

Let’s write a simple XQuery program in Stylus Studio which runs the same query. Using a very handy JSON to XML converter engine, we can quickly generate an XML document.

Now that we know how to invoke the Google API, we should encapsulate the Google service into an XQuery library which can be called by other XQuery programs. In the following screenshot we can see a variety of functions like queryByISBN, queryByTitle and utility function to format ISBN numbers properly.

Now let’s go back to our original list of books which is in plain text and see how we can turn it into XML and use it as input to an XQuery program.

In the final screen, we have a very simple XQuery program which takes a list of titles and returns a far more compressive flat file.

For “Extra Credit” see if you can put the results in a Spreadsheet or a Database. Post your results on SSDN!




We hope you enjoyed reading this tutorial. If you have any questions or feedback on this tutorial do not hesitate to contact us. If you like this article, help us get the word out! Click the "+1" button on the top of our website (next to the logo) to +1 us with your Google+ account.

- Stylus Studio Team


 Technical Support


 Follow us on Twitter


 Connect on Facebook
 

PURCHASE STYLUS STUDIO ONLINE TODAY!!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Try Stylus Powerful XQuery IDE

Download a free trial of our award-winning IDE for XQuery today!

Attend a Live Webinar This Week!

Learn about Stylus Studio's unique features and benefits in just under an hour. Register for the Stylus Studio QuickStart Training WebCast!

Why Pay More for XML Tools?

With Stylus Studio® X16 XML Enterprise Suite, you get the most comprehensive XML tool suite at one incredibly low price. Value: it's just one of many reasons why smart XML developers are choosing Stylus Studio!

Top Ten XQuery Trends

Read about the top 10 XQuery Trends and how they will impact change the way enterprise software applications are built.

 
Free Stylus Studio XML Training:
W3C Member