Creating URL Queries
Overview
Teaching: 20 min
Exercises: 20 minQuestions
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
Orbis
Reading Documentation
- Look through the params
- What types of search parameters are available?
- Do they match what you need?
- What is the Endpoint (Base URL)?
- Look for sample requests & responses
- What kind of data does it return?
- Is it what you’re looking for?
- Look for restrictions
- Is it free?
- Does it require a key or permissions?
- Do they impose a limit?
Creating a Query
- National Weather Service API
- Documentation: https://forecast-v3.weather.gov/documentation?redirect=legacy
- Endpoint/Base URL: https://api.weather.gov
Let’s create a query
Run this query: https://api.weather.gov/stations?limit=10&state=CT
- What do the results show?
- What is the Station Identifier for Tweed-New Haven Airport?
- Write a query that returns all active weather alerts for California. (Hint: use ‘area’ not ‘state’)
Solution
- Shows 10 currently-active weather stations in Connecticut and includes metadata about each station.
- KHVN
- 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