🚀 Stop 3: San Francisco
Sending Requests & Receiving Responses
Meet Your San Francisco Sports Teams
1 Understanding HTTP Communication
How Computers Talk to Each Other
When you want stadium data, your computer (the client) needs to communicate with the server that stores the information. This happens through HTTP (Hypertext Transfer Protocol) - the language computers use to request and send data over the internet.
HTTP GET Request
A GET request is like asking the server a question: "Can I please have information about this stadium?" The server then looks up the information and sends it back to you.
2 Using HTTP Client Libraries
What Are HTTP Client Libraries?
HTTP client libraries are tools that make it easy to send requests and receive responses. Instead of writing complicated code, you can use simple functions like Python's requests library or JavaScript's fetch() function.
📚 Example Code:
Python Example:
# Send GET request to API
response = requests.get('https://api.sfsports.com/v1/stadium/levis_stadium')
# Check if request was successful
if response.status_code == 200:
data = response.json() # Convert JSON to Python dictionary
print(data)
JavaScript Example:
fetch('https://api.sfsports.com/v1/stadium/levis_stadium')
.then(response => response.json()) // Parse JSON
.then(data => console.log(data)) // Use the data
.catch(error => console.error(error));
3 Send a Request & See the Response
Try It Yourself!
Select a stadium below and click "Send Request" to see how your computer communicates with the server. Watch for the HTTP status code and the JSON response!
4 Understanding HTTP Status Codes
What Are Status Codes?
Every HTTP response includes a status code that tells you whether the request was successful or if something went wrong. Here are the most common ones:
✅ 200 OK
⚠️ 404 Not Found
🔒 401 Unauthorized
⚙️ 500 Server Error
🎯 What You Learned: Sending an HTTP request is the physical act of communicating with a server. You use HTTP client libraries (like requests or fetch) to send GET requests. The server responds with a status code (like 200 OK) and the requested data in JSON format!
🎯 Test Your Knowledge: Quick Quiz
🎉 Quiz Complete!
Great job!