Using an API like a developer

By Tom Johnson / @tomjohnson
idratherbewriting.com


Slides available at
idratherbewriting.com/slides/using_api_like_developer/

Dev scenario: Retrieve weather info

Simple implementation

Fancy implementation

Choosing a weather API

Activity 2a: Explore the OpenWeatherMap API

Activity 2b: Get OpenWeatherMap authorization keys

Submitting requests

Activity 2c: Make requests with Postman

curl


curl --request GET "https://api.openweathermap.org/data/2.5/weather?zip=95050&units=imperial&appid=APIKEY"

  

cURL commands

Command Description
--location Submits request to redirect
-X, --request The HTTP method to use
-i, --include Include response headers
-d, --data Include data to post
-H, --header Submit header
@filename Load content from a file

Analyze responses

JSON objects:


    {
    "key1":"value1",
    "key2":"value2"
    }
    

JSON arrays:


    ["first", "second", "third"]
    

Activity 2d: Make requests with curl

Log the response to the console

Use dot notation to access values

Temperature:


                response.main.temp
                

Wind speed:


    response.wind.speed
    

Wind direction:


response.wind.deg

Activity 2e: Make an API request on a web page

Questions?