APIs • JSON • Web Data • Automation

APIs feel like magic once they click.

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.

Main idea: APIs let my code use other systems as building blocks. The important skills are understanding endpoints, requests, responses, JSON, authentication, rate limits, and safe handling of API keys.
My script Python, JavaScript, curl, Flask, or another program.
API request Ask a service for data or an action.
JSON response Structured data my program can read.
Useful result Weather, movie data, AI output, dashboards, alerts, or automation.
APIs are the bridge between my code and useful external services.

What is an API?

API stands for Application Programming Interface. That sounds abstract, but the idea is simple: an API is a controlled doorway into another system.

Request

My code asks

A program sends a request to an endpoint, usually with a URL, headers, parameters, and sometimes a body.

Response

The service answers

The API returns structured data, usually JSON, with a status code that says whether the request worked.

Automation

My program uses it

Once the data comes back, my program can display it, save it, filter it, summarize it, or use it to trigger another action.

Why APIs feel magical

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.

01

Ask for data

Get forecasts, movie details, alerts, search results, coordinates, prices, or metadata.

02

Parse JSON

Turn the response into variables, lists, dictionaries, tables, or cards.

03

Build something

Use the data in a website, script, CLI tool, dashboard, alert system, or project.

04

Automate it

Run it on a schedule, connect it to a server, or combine it with another API.

API vocabulary that matters

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.

My basic API workflow

The workflow is the same whether I am using Weather.gov, TMDB, OpenAI, GitHub, Cloudflare, or another service.

01

Read the docs

Find the endpoint, method, authentication rules, parameters, and response format.

02

Test with curl

Make one simple request in the terminal before writing a full program.

03

Parse the JSON

Use Python, JavaScript, or another language to extract the fields I need.

04

Build the feature

Display the result, save it, trigger an alert, or combine it with another system.

My rule: do one successful request manually before building the whole app. If the basic request does not work, the app will not work either.

Start with curl

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
Useful combo: curl gets the data, and jq makes the JSON readable.

JSON is the language of many APIs

JSON looks like JavaScript object syntax, but it is used by many languages. Python reads it like dictionaries and lists.

JSON response

What the API returns

{
  "title": "The Matrix",
  "year": 1999,
  "genres": ["Action", "Sci-Fi"],
  "rating": 8.7
}
Python access

How code reads it

movie["title"]
movie["year"]
movie["genres"][0]
movie["rating"]

Three APIs that make the idea click

These are good examples because each one teaches a different API lesson.

Weather.gov

Public data API

Weather.gov is a good first API because it exposes real public weather data and teaches endpoints, JSON, headers, and forecast URLs.

TMDB

Media database API

TMDB is useful for movie apps because it provides movie, TV, person, image, discovery, and search data through documented endpoints.

OpenAI API

AI as a service

The OpenAI API lets a program send input to a model and get generated text, structured output, summaries, classifications, or tool-like behavior back.

Example 1: Weather.gov

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
Important: Weather.gov expects a User-Agent header that identifies the application. This is not an API key, but it tells the service what app is making the request.

Weather.gov with Python

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()
Project idea: build a tiny terminal weather app that prints the next three forecast periods for a saved location.

Example 2: TMDB API

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
API key rule: never commit API keys, bearer tokens, or secrets to GitHub. Use environment variables or a private .env file that is ignored by Git.

TMDB with Python

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()
LaunchShell connection: this would pair well with the Java Movie Database CLI project. A future version could use an API to fetch movie metadata instead of relying only on manual input or a TSV file.

Example 3: OpenAI API

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."
  }'
Good use case: use the OpenAI API during project creation, admin tooling, summaries, clue generation, study helpers, and content drafting. Do not expose the API key in frontend JavaScript.

OpenAI API with Python

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)
Security rule: backend code can safely call the API with a secret key. Static HTML pages should not contain secret keys because anyone can view the page source.

API keys and environment variables

API keys are like passwords for services. They should not be pasted into public code, static HTML, screenshots, GitHub repos, or browser JavaScript.

Better

Use environment variables

export OPENAI_API_KEY="secret"
export TMDB_BEARER_TOKEN="secret"

python3 app.py
Avoid

Hardcoding secrets

# Bad idea
api_key = "paste-real-key-here"
Git rule: if a project uses a .env file, add .env to .gitignore before committing.

GET vs POST

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 I should recognize

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.

Beginner mistakes to avoid

Most beginner API problems are predictable.

Avoid this

Common mistakes

  • Committing API keys to GitHub.
  • Calling paid APIs in a loop without limits.
  • Ignoring status codes.
  • Assuming every response has the fields I expected.
  • Putting secret keys inside frontend JavaScript.
  • Not reading the API terms or rate-limit rules.
Do this instead

Better habits

  • Use environment variables for secrets.
  • Start with one curl request.
  • Pretty-print JSON with jq.
  • Use response.raise_for_status() in Python.
  • Cache results when possible.
  • Handle missing fields safely.

Good beginner API projects

These are practical projects that would fit LaunchShell well.

1

Terminal weather app

Use Weather.gov to print a short forecast for a saved latitude and longitude.

2

Movie lookup tool

Use TMDB to search for movies and display title, year, overview, rating, and poster path.

3

AI study helper

Use the OpenAI API to summarize notes, generate quiz questions, or explain code.

4

Static site data builder

Use an API in a local script to generate JSON files that power a static HTML page.

How this connects to LaunchShell

APIs fit perfectly with the LaunchShell style because they turn small projects into real systems.

01

Static site

Use APIs locally to generate JSON, then publish static pages safely.

02

Python scripts

Build small tools that fetch data, clean it, and save useful output.

03

Flask apps

Use a backend server to safely call APIs without exposing keys.

04

Cybersecurity

Learn headers, authentication, tokens, status codes, rate limits, and logs.

API cheat sheet

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

Final idea

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.