BLACK FRIDAY: Save 50% on all my Swift books and bundles! >>

Proyect 10: Sending and receiving Codable Data. How to get an api to try ?

Forums > 100 Days of SwiftUI

I am in proyect 14 now...

I am trying most of the things Paul explains in a simple App that I am creating...

In it, I have some examples made by my own to try what I am learning...

When I was in proyect 10, he explained how to receive and send Codable data using a Json file that he has as an example... Also he used a Json file in the moonshot proyect...

I want to try with a Json file instead of with my examples, to learn more about Json. But I don't know how to get it... the ones I have tried are the ones he has given to us...

The app is about books...

I have a struct called book with several properties. Could I get an api (for example google books api) to get the information of my books ? (to get from that api the description of the book, the author,... ). That is the way I must do it to get information odf the books... am I right??? To be able to work with real data instead of just with my examples...

I am totally lost with this...

How could I get that api or how could I get what I am looking for?

   

Could I get an api (for example google books api) to get the information of my books ?

Searching for Information on the Web

To get a listing of books in json format, you have to find some person, company, or business who published a listing of books in json format. Use the Google, and search for one. Here's an example. I searched for NYT Best Sellers JSON.

The Google coughed up a nice url from the New York Time's developers page, including a URL where I could download a list of books currently in their famous Best Seller's list.
See -> httpx://developer.nytimes.com/docs/books-product/1/routes/lists/best-sellers/history.json/get

The small issue you will face with the NY Time's interface is that you need an authorization key. Of course this is to keep unruly applications from making millions of queries each day. But you should be able to find other URLs for similar data.

Authorization Key

Please note that Google also requires an authentication key to access their API. Ususally you can sign up for an API authorization key which will allow a few hundred searchs each day. Once you're ready to publish an application, you'll need to opt in to a pay-for-subscription service.

Keep coding!

Good luck! Please return here and share the URL that you found, along with some nice code examples so we all can learn from your adventure!

   

Thanks for the tips !!!

I had no idea where to start ! Now I have my authorization Key to use google books api !!!! Totally new for me.

Now I can search for example for an author's books...

I. have some questions... I have been trying to find the aswers, but I haven't been lucky...

1.- if I search for books of an author, it shows just the books in my language... how could I do to get all the books of that author and not just the ones in my language ? For example:

See -> httpx://www.googleapis.com/books/v1/volumes?q=authors:shari+lapena&key=MYKEY It just shows the books of Shari Lapena written in Spanish...

2.- And how could I search for the books of two different authors??? I have tried with "&" but it doesn't work... httpx://www.googleapis.com/books/v1/volumes?q=authors:shari+lapena&stephen+king&key=MYKEY

Thanks!!!!

   

@kitty is branching out! Nice!

how could I [find] all the author's books and not just the ones in my language ?

Please note, this is a forum for Swift and SwiftUI assistance! You are quickly dropping into another rabbit hole of learning. But your answers may be found in Google API forums, not in HackingWithSwift forums!

RTFM (Read the Friendly Manual)

Google documentation has this API-specific query parameter that may, or may not, help you.

langRestrict

  • Restrict the search results to those with certain language by specifying langRestrict to a two-letter ISO-639-1 code such as "es" or "fi"

Maybe to answer your question you want two queries that you mash together?
One looks for English "en" the other looks for Finnish "fi" ?

// Try this query to find books by Shari Lapena, but published in English.

//                                              Note the restriction parameter 👇🏼
httpx://www.googleapis.com/books/v1/volumes?q=authors:shari+lapena&langRestrict=en

Keep Coding!

Please return here and share some cool google api magic! 🪄

   

@kitty wonders:

And how could I search for the books of two different authors??? I have tried with "&" but it doesn't work.....

Please note: Unless the two collaborated, you will probably find there are exactly zero books written by Stephen King and Shari Lapena

Stephen King did collaborate with his son Joe Hill and another book with Peter Straub. But I'm sure he didn't write a book with Sra Lapena.

By the way, Joe's middle name is Hillstrom. I suppose he picked Joe HIll as a suitable name for publishing. "Joe King" might have unintended interpretations.

   

@kitty wonders:

•••••

And how could I search for the books of two different authors??? I have tried with "&" but it doesn't work.....

•••••

What I wanted to get is a list of the books written by Shari Lapena and the books written by stephen king... no by both of them together

I use "&" to try something, but not meaning written by both of them... httpx://www.googleapis.com/books/v1/volumes?q=authors:shari+lapena&stepehn+King

what I wanted is getting the books of both authors (not the ones written by both)

I have tried to find the answer usong google, but I can't find it...

Sorry if this is not the place to ask. I thought it would be, because I have learned about it with the "100 days of swiftui" course...

and I am just trying to practique what I am learning...

Thanks for your advice!

   

Save 50% in my WWDC sale.

SAVE 50% All our books and bundles are half price for Black Friday, so you can take your Swift knowledge further without spending big! Get the Swift Power Pack to build your iOS career faster, get the Swift Platform Pack to builds apps for macOS, watchOS, and beyond, or get the Swift Plus Pack to learn advanced design patterns, testing skills, and more.

Save 50% on all our books and bundles!

Reply to this topic…

You need to create an account or log in to reply.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.