San Francisco - Sending Requests & Receiving Responses

🚀 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.

💻
Your Computer
Sends HTTP Request
🌐
Server
Processes Request
📦
Response
Returns Data

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:

import requests

# 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:

// Send GET request to API
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!

Select a stadium above to see the request URL...

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

Success! The server found the data and is sending it to you.

⚠️ 404 Not Found

The server couldn't find what you requested. Check your URL!

🔒 401 Unauthorized

You don't have permission. Did you include your API key?

⚙️ 500 Server Error

Something went wrong on the server's end. Try again later.

🎯 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

Question 1 of 4
What does HTTP stand for?
A) HyperText Transmission Protocol
B) HyperText Transfer Protocol
C) HighText Transfer Process
D) HyperType Transfer Protocol
Question 2 of 4
Which HTTP status code means "Success"?
A) 404
B) 500
C) 200
D) 401
Question 3 of 4
What is the purpose of an HTTP client library like 'requests' or 'fetch'?
A) To store data in a database
B) To make it easy to send requests and receive responses
C) To create websites
D) To write HTML code
Question 4 of 4
In the HTTP communication flow, what happens after the server processes a request?
A) The client sends another request
B) The server deletes the data
C) The server sends back a response with data
D) The connection is closed permanently

🎉 Quiz Complete!

0/4

Great job!