Win a copy of Beginning Java 17 Fundamentals: Object-Oriented Programming in Java 17 this week in the Java in General forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

cannot get data (temprature) from API

 
Hany Taha
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I use https://openweathermap.org/current#zip to get some data (temperature) by letting user enter the Zip Code of his country.
I expect to return a response that I can extract the temperature from it. Instead I get the following response
I can't get any data from it. Any advice how I can get temperature of that response?
 
Bear Bibeault
Sheriff
Posts: 67620
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You are not using the fetch API correctly. You need to extract the JSON from the stream. Please see example here.
 
Tim Holloway
Saloon Keeper
Posts: 24898
174
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hany, Ron is right. You don't want to publish your Openweathermap access key on a public site where anyone can pick it up and abuse it. Your post is not presently visible to most people for your protection. If you can just "X" out that key, we'll un-hide it.

In the mean time, let me show you how I do something similar. It uses Axios and it polls the US National Weather Service servers to get an hour-by-hour forecast of expected weather conditions. It's actually used as part of a web service that gets queried by a little eInk display on my wall and the reason it does the strange things it does is because it's designed to get a pessimistic idea of what the weather will be like during the work day so that the display can be checked on the way out the door in the morning. The code runs at 4 a.m. each morning and the results go into a database for the display to use - the display has a clock and thus updates once a minute. I didn't want to annoy the weather server that frequently.

Although since work-from-home became the norm, I supposed I should change it a bit.

Anyway, here it is.
 
Campbell Ritchie
Marshal
Posts: 74780
336
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please don't edit your post after it has been replied to; that makes it difficult to understand the replies. I am refusing the edits; please go back, delete the key, and change nothing else.
 
Hany Taha
Greenhorn
Posts: 11
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks guys. Problem solved by chaining the promise and extract JSON from the stream
 
WHAT is your favorite color? Blue, no yellow, ahhhhhhh! Tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic