Creating URL Queries

Overview

Teaching: 20 min
Exercises: 20 min
Questions
  • What are URL query strings?

  • How can you make API requests?

  • How do you interperet API documentation?

Objectives
  • Explain URL query strings

  • Explain how to create API queries

  • Explain how to read and interperet API documentation

URL Query Strings

YouTube

https://www.youtube.com/watch?v=s7wmiS2mSXY&t=1m45s youtube URL

Orbis

https://orbis.library.yale.edu/vwebv/searchResults?searchArg=python&searchCode=GKEY&searchType=0&recCount=10 Orbis url

Reading Documentation

Creating a Query

Let’s create a query

Run this query: https://api.weather.gov/stations?limit=10&state=CT

  1. What do the results show?
  2. What is the Station Identifier for Tweed-New Haven Airport?
  3. Write a query that returns all active weather alerts for California. (Hint: use ‘area’ not ‘state’)

Solution

  1. Shows 10 currently-active weather stations in Connecticut and includes metadata about each station.
  2. KHVN
  3. https://api.weather.gov/alerts?active=1&area=CA or https://api.weather.gov/alerts/active?area=CA or https://api.weather.gov/alerts/active/area/CA

Key Points

  • REST APIs use query stings to make requests

  • URL queries are found all across the web