My code asks
A program sends a request to an endpoint, usually with a URL, headers, parameters, and sometimes a body.
An API is a way for one program to talk to another program. Instead of scraping a web page, copying data by hand, or building everything from scratch, my code can ask another service for structured data and get a useful response back.
This is where programming starts to feel powerful. A script can ask Weather.gov for a forecast, ask TMDB for movie data, or ask the OpenAI API to generate, classify, summarize, or transform text.
API stands for Application Programming Interface. That sounds abstract, but the idea is simple: an API is a controlled doorway into another system.
A program sends a request to an endpoint, usually with a URL, headers, parameters, and sometimes a body.
The API returns structured data, usually JSON, with a status code that says whether the request worked.
Once the data comes back, my program can display it, save it, filter it, summarize it, or use it to trigger another action.
APIs are powerful because they let small programs do big things. I do not need to own the weather station, movie database, or AI model. I just need to know how to ask the API correctly.
Get forecasts, movie details, alerts, search results, coordinates, prices, or metadata.
Turn the response into variables, lists, dictionaries, tables, or cards.
Use the data in a website, script, CLI tool, dashboard, alert system, or project.
Run it on a schedule, connect it to a server, or combine it with another API.
Most API confusion comes from vocabulary. These are the terms I need first.
| Term | Meaning | Example |
|---|---|---|
| Endpoint | A specific API URL that does one job. | /forecast, /movie/search, /responses |
| Method | The action type used in the request. | GET reads data. POST sends data. |
| Header | Extra request information sent with the API call. | Authorization, User-Agent, Content-Type |
| Query parameter | A value added to the URL to filter or modify the request. | ?query=matrix, ?units=us, ?page=1 |
| JSON | A common structured data format used by APIs. | { "title": "The Matrix", "year": 1999 } |
| API key | A secret token that identifies my app or account. | Used by APIs like OpenAI and TMDB. |
| Status code | A number that explains whether the request worked. | 200 success, 401 unauthorized, 404 not found. |
The workflow is the same whether I am using Weather.gov, TMDB, OpenAI, GitHub, Cloudflare, or another service.
Find the endpoint, method, authentication rules, parameters, and response format.
Make one simple request in the terminal before writing a full program.
Use Python, JavaScript, or another language to extract the fields I need.
Display the result, save it, trigger an alert, or combine it with another system.
curl is one of the best ways to learn APIs because it shows the request and
response without hiding the details behind a library.
# Basic GET request
curl https://api.example.com/data
# Show response headers too
curl -i https://api.example.com/data
# Send a header
curl -H "Accept: application/json" https://api.example.com/data
# Pretty-print JSON with jq
curl https://api.example.com/data | jq
curl gets the data, and jq makes
the JSON readable.
JSON looks like JavaScript object syntax, but it is used by many languages. Python reads it like dictionaries and lists.
{
"title": "The Matrix",
"year": 1999,
"genres": ["Action", "Sci-Fi"],
"rating": 8.7
}
movie["title"]
movie["year"]
movie["genres"][0]
movie["rating"]
These are good examples because each one teaches a different API lesson.
Weather.gov is a good first API because it exposes real public weather data and teaches endpoints, JSON, headers, and forecast URLs.
TMDB is useful for movie apps because it provides movie, TV, person, image, discovery, and search data through documented endpoints.
The OpenAI API lets a program send input to a model and get generated text, structured output, summaries, classifications, or tool-like behavior back.
Weather.gov is a good API for learning because it returns real forecast data. The usual pattern is: ask for grid metadata using latitude and longitude, then follow the forecast URL returned by the API.
# Step 1: get forecast metadata for a latitude/longitude
curl -H "User-Agent: LaunchShellAPIPractice (you@example.com)" \
"https://api.weather.gov/points/40.7128,-74.0060" | jq
# Step 2: use the forecast URL returned in the JSON
curl -H "User-Agent: LaunchShellAPIPractice (you@example.com)" \
"https://api.weather.gov/gridpoints/OKX/33,37/forecast" | jq
User-Agent header that
identifies the application. This is not an API key, but it tells the service what app is
making the request.
Once the curl request works, Python can make the same request and extract fields from the JSON response.
import requests
headers = {
"User-Agent": "LaunchShellAPIPractice (you@example.com)"
}
points_url = "https://api.weather.gov/points/40.7128,-74.0060"
points = requests.get(points_url, headers=headers, timeout=10)
points.raise_for_status()
data = points.json()
forecast_url = data["properties"]["forecast"]
forecast = requests.get(forecast_url, headers=headers, timeout=10)
forecast.raise_for_status()
periods = forecast.json()["properties"]["periods"]
for period in periods[:3]:
print(period["name"])
print(period["temperature"], period["temperatureUnit"])
print(period["shortForecast"])
print()
TMDB is useful for movie projects because it can turn a simple title search into structured movie data: titles, release dates, summaries, ratings, poster paths, genres, and related IDs.
# Store the token in an environment variable, not directly in code
export TMDB_BEARER_TOKEN="paste_token_here"
# Search for a movie
curl --request GET \
--url "https://api.themoviedb.org/3/search/movie?query=The%20Matrix&include_adult=false&language=en-US&page=1" \
--header "Authorization: Bearer $TMDB_BEARER_TOKEN" \
--header "accept: application/json" | jq
.env file that is ignored by Git.
This connects directly to a movie database project. Instead of manually typing every movie field, a script could search TMDB and fill in basic metadata.
import os
import requests
token = os.environ["TMDB_BEARER_TOKEN"]
headers = {
"Authorization": f"Bearer {token}",
"accept": "application/json"
}
params = {
"query": "The Matrix",
"include_adult": "false",
"language": "en-US",
"page": 1
}
response = requests.get(
"https://api.themoviedb.org/3/search/movie",
headers=headers,
params=params,
timeout=10
)
response.raise_for_status()
results = response.json()["results"]
for movie in results[:5]:
print(movie["title"], movie.get("release_date", "unknown"))
print(movie.get("overview", "")[:160])
print()
The OpenAI API is different from a normal data API. Instead of only returning stored facts, it can generate or transform text based on input. That makes it useful for drafting, sorting, classifying, summarizing, building study tools, and creating helper features inside apps.
# Store the key outside the code
export OPENAI_API_KEY="paste_key_here"
# Example request
curl https://api.openai.com/v1/responses \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $OPENAI_API_KEY" \
-d '{
"model": "gpt-5.5",
"input": "Explain APIs in one paragraph for a beginner."
}'
In Python, the basic pattern is: load the API key from the environment, create a client, send input, and print the model output.
from openai import OpenAI
client = OpenAI()
response = client.responses.create(
model="gpt-5.5",
input="Give me three beginner project ideas for learning APIs."
)
print(response.output_text)
API keys are like passwords for services. They should not be pasted into public code, static HTML, screenshots, GitHub repos, or browser JavaScript.
export OPENAI_API_KEY="secret"
export TMDB_BEARER_TOKEN="secret"
python3 app.py
# Bad idea
api_key = "paste-real-key-here"
.env file, add
.env to .gitignore before committing.
Most beginner API work starts with GET and POST.
| Method | What it usually means | Example use |
|---|---|---|
| GET | Read or fetch data. | Get a forecast, search for a movie, list records. |
| POST | Send data to create something or ask for processing. | Send a prompt, create a record, submit a form, classify text. |
| PUT/PATCH | Update existing data. | Modify a saved item or update a setting. |
| DELETE | Remove something. | Delete a record through an API. |
Status codes are the API's first explanation of what happened.
| Code | Meaning | What I check |
|---|---|---|
| 200 | Success. | The request worked. Now inspect the JSON. |
| 400 | Bad request. | Check parameters, JSON body, or URL formatting. |
| 401 | Unauthorized. | Check API key, token, or authorization header. |
| 403 | Forbidden. | The key may not have permission, or the endpoint may be restricted. |
| 404 | Not found. | Check the endpoint path or requested resource ID. |
| 429 | Rate limited. | Slow down requests, cache results, or check the API's rate-limit rules. |
| 500 | Server error. | The problem may be on the API provider's side. |
Most beginner API problems are predictable.
jq.response.raise_for_status() in Python.These are practical projects that would fit LaunchShell well.
Use Weather.gov to print a short forecast for a saved latitude and longitude.
Use TMDB to search for movies and display title, year, overview, rating, and poster path.
Use the OpenAI API to summarize notes, generate quiz questions, or explain code.
Use an API in a local script to generate JSON files that power a static HTML page.
APIs fit perfectly with the LaunchShell style because they turn small projects into real systems.
Use APIs locally to generate JSON, then publish static pages safely.
Build small tools that fetch data, clean it, and save useful output.
Use a backend server to safely call APIs without exposing keys.
Learn headers, authentication, tokens, status codes, rate limits, and logs.
This is the short version I would keep nearby.
# Basic request
curl https://api.example.com/data
# Include headers
curl -H "Accept: application/json" https://api.example.com/data
# Include an API bearer token
curl -H "Authorization: Bearer $API_TOKEN" https://api.example.com/data
# Pretty-print JSON
curl https://api.example.com/data | jq
# Python requests pattern
import requests
response = requests.get(url, headers=headers, params=params, timeout=10)
response.raise_for_status()
data = response.json()
# Environment variables
export API_TOKEN="secret"
# Git safety
echo ".env" >> .gitignore
APIs are one of the biggest jumps from writing isolated code to building real tools. Once I understand requests, responses, JSON, keys, headers, and status codes, my programs can pull weather data, search movie databases, use AI models, power dashboards, generate static site content, and automate work that would be painful to do by hand.