1

I am building a book app with Flutter for Android and iOS. I am using Google Books API to retrieve book data, but I have noticed something strange which I dont understand. If we look at the book data displayed in chrome browser (https://www.googleapis.com/books/v1/volumes/b3GuDwAAQBAJ), we can see that the content (eg. field categories) is different than what I get when calling http response and printing out it's body. In addition to that, it also seems like unicode characters (eg. from description) are not sent.

Data displayed on the browser

The obtained Response body

The code that I'm using to get the API data can be seen below:

Response result = await http.get(Uri.parse(url), headers: {'content-type': 'application/json; charset=utf-8'});
if (result.statusCode == 200) {
  final jsonResponse = jsonDecode(utf8.decode(result.bodyBytes));
  if (jsonResponse["totalItems"] == 0) {
    return List.empty();
  }

  //this prints out the content in above image
  print(result.body.toString());

  final booksMap = jsonResponse['items'];
  List<dynamic> books = booksMap.map((i) => Book.fromJson(i)).toList();
  return books;
Lulek
  • 21
  • 3

2 Answers2

0

It seems that https://www.googleapis.com/books/v1/volumes/b3GuDwAAQBAJ gives different data than your usual search query (eg. https://www.googleapis.com/books/v1/volumes?q=isbn:9780143123231). I do not know the reason why.

Lulek
  • 21
  • 3
0

You can see the API response in raw form due to which unicode are present

Raw Form image from browser

but when you get api response you can parse into json, By parsing json that unicodes are removed and data is in proper format

if you use json Formatter extension in chrome you can see that the data in chrome in Json form and the response from api when you are hitting api by code are same.

Data in Json Form in Browser

in the application code , you set headers: {'content-type': 'application/json; thats why u received Json data code. and its not problem because you will use this data into your application,

you can see more content types here

Blockquote

  • Welcome to Stack Overflow. Can I ask you a favor? Can you [edit] your answer to include the data in _text_ format, instead of as _screenshots_? You can use Markdown to format them as code for readability. That will make the data easier to read and reference. – Jeremy Caney Feb 20 '22 at 00:28