DevX JS - W3C8 - API's and JSON.pptx (1)
DevX JS - W3C8 - API's and JSON.pptx (1)
https://codebeautify.org/jsonvalidator
APIs
APIs
User
API stands for Application Program Interface. It is the
channel of communication between two computer
programs.
APIs take in requests and give out data. This data is in some format. (Eg, JSON, XML, etc.)
Some APIs are similar to others. But each API is unique. They often have a website or
documentation page to help users understand how to use it. As you work with more APIs you
will see similarities and differences between them.
At the end of the day, you need to read the documentation to figure it out…
API Keys
API Keys
API keys are used by web services to
allow people to access an API.
https://api.openweathermap.org/data/2.5/weather?q=Bishkek&appid=YOURAPIKEY
Using OpenWeather
Using OpenWeather
1. We have a working API call. Now we
can write some javascript code that {
"coord": { "visibility": 10000,
displays the information on the page. "lon": 74.59, "wind": {
d. main description ],
} "sys": {
"type": 1,
e. wind speed "base": "stations", "id": 8871,
"main": { "country": "KG",
"temp": 279.26, "sunrise": 1668909575,
"feels_like": 277.22, "sunset": 1668944105
"temp_min": 279.26, },
"temp_max": 279.26, "timezone": 21600,
https://api.openweathermap.org "pressure": 1025, "id": 1528675,
"humidity": 75, "name": "Bishkek",
/data/2.5/weather?q=Bishkek&ap "sea_level": 1025, "cod": 200
"grnd_level": 935 }
pid=YOURAPIKEY
},
Building an App
Building an App
1. Let's build an app to check the
weather at your location. {
"coord": { "visibility": 10000,
2. It will need an input for the location. "lon": 74.59, "wind": {
d. wind speed ],
} "sys": {
"type": 1,
e. time "base": "stations", "id": 8871,
"main": { "country": "KG",
5. You should be able to change the "temp": 279.26, "sunrise": 1668909575,
location and have new data show up. "feels_like": 277.22, "sunset": 1668944105
"temp_min": 279.26, },
"temp_max": 279.26, "timezone": 21600,
"pressure": 1025, "id": 1528675,
"humidity": 75, "name": "Bishkek",
"sea_level": 1025, "cod": 200
"grnd_level": 935 }
},
Q&A