🌐How the Internet Works (HTTP Basics)
URLs, requests, responses, and headers — what happens when you call an API
How the Internet Works (HTTP Basics)
Every time you use Claude's API, something invisible happens between your computer and Anthropic's servers. Understanding HTTP is the key to unlocking that mystery.
What Happens When You Visit a Website?
Let's trace the journey step by step:
┌──────────┐ ┌──────────────┐ ┌──────────────┐
│ You │ -----> │ Internet │ -----> │ Server │
│ (Browser)│ │ (Network) │ │ (Website) │
└──────────┘ └──────────────┘ └──────────────┘
│ │
│ 1. You type a URL │
│ 2. Browser sends a REQUEST --------> │
│ 3. Server processes it │
│ <------- 4. Server sends a RESPONSE -------- │
│ 5. Browser displays the page │
│ │
This entire conversation uses HTTP — a protocol (a set of rules) that your browser and the server agree on.
What is a URL?
A URL (Uniform Resource Locator) is an address that tells your browser exactly where to find something on the internet.
Let's break one down:
https://api.anthropic.com/v1/messages?model=claude-3
└─┬──┘ └──────┬──────────┘└────┬────┘└──────┬──────┘
│ │ │ │
Protocol Domain Path Parameters
| Part | Example | What it does |
|---|---|---|
| Protocol | https:// | How to communicate (secure HTTP) |
| Domain | api.anthropic.com | Which server to talk to |
| Path | /v1/messages | Which resource on that server |
| Params | ?model=claude-3 | Extra details (filters, options) |
Think of it like a postal address:
- Protocol = how to deliver (express mail vs regular)
- Domain = the building address
- Path = the apartment number
- Params = special delivery instructions
HTTP vs HTTPS
| Feature | HTTP | HTTPS |
|---|---|---|
| Full name | HyperText Transfer Protocol | HyperText Transfer Protocol Secure |
| Encrypted | No | Yes (uses TLS/SSL) |
| Safe for APIs | No | Yes |
| Port | 80 | 443 |
Always use HTTPS when working with APIs. Claude's API only accepts HTTPS.
HTTP = sending a postcard (anyone can read it)
HTTPS = sending a sealed letter (only you and the recipient can read it)
What is a Request?
A request is you asking the server for something. Every request has:
┌─────────────────────────────────────────────┐
│ HTTP Request │
├─────────────────────────────────────────────┤
│ Method: POST │
│ URL: https://api.anthropic.com/v1/messages │
│ │
│ Headers: │
│ Content-Type: application/json │
│ x-api-key: sk-ant-xxxxx │
│ │
│ Body: │
│ { │
│ "model": "claude-sonnet-4-20250514", │
│ "messages": [ │
│ { "role": "user", │
│ "content": "Hello!" } │
│ ] │
│ } │
└─────────────────────────────────────────────┘
Four key parts:
- Method — what action you want (GET, POST, etc.)
- URL — where to send it
- Headers — metadata about the request
- Body — the actual data (not always needed)
What is a Response?
A response is the server's answer. It also has structure:
┌─────────────────────────────────────────────┐
│ HTTP Response │
├─────────────────────────────────────────────┤
│ Status: 200 OK │
│ │
│ Headers: │
│ Content-Type: application/json │
│ x-request-id: req_abc123 │
│ │
│ Body: │
│ { │
│ "id": "msg_123", │
│ "type": "message", │
│ "content": [ │
│ { "type": "text", │
│ "text": "Hello! How can I help?" } │
│ ] │
│ } │
└─────────────────────────────────────────────┘
HTTP Methods
These tell the server what you want to do:
| Method | Action | Example | Analogy |
|---|---|---|---|
| GET | Read | Get a list of models | Reading a menu |
| POST | Create | Send a message to Claude | Placing an order |
| PUT | Update | Replace entire user profile | Rewriting a document |
| PATCH | Partial | Update just the user's name | Editing one line |
| DELETE | Remove | Delete a fine-tuned model | Throwing away a file |
With Claude's API, you'll use POST most of the time — you're sending a message and getting a response back.
GET = "Can I see the menu?"
POST = "I'd like to order this."
PUT = "Replace my entire order with this new one."
PATCH = "Actually, change just the drink."
DELETE = "Cancel my order."
Status Codes
The server's status code tells you what happened — at a glance:
2xx = Success (You got what you wanted)
3xx = Redirect (Look somewhere else)
4xx = Client error (You made a mistake)
5xx = Server error (The server broke)
Here are the ones you'll encounter most with APIs:
| Code | Meaning | Emoji | When it happens |
|---|---|---|---|
| 200 | OK | ✅ | Request succeeded |
| 201 | Created | 🆕 | New resource was created |
| 400 | Bad Request | ❌ | Your request has errors (bad JSON, etc.) |
| 401 | Unauthorized | 🔒 | Invalid or missing API key |
| 403 | Forbidden | 🚫 | Valid key but no permission |
| 404 | Not Found | 🔍 | The endpoint doesn't exist |
| 429 | Rate Limited | ⏳ | Too many requests — slow down |
| 500 | Server Error | 💥 | Something broke on the server side |
Pro tip: When you get a 429 from Claude's API, wait and retry. Most SDKs handle this automatically with exponential backoff.
What Are Headers?
Headers are metadata — extra information about the request or response. They travel alongside the body but aren't the main content.
┌─────────────────────────────────────────┐
│ Think of headers like an envelope: │
│ │
│ To: api.anthropic.com │
│ From: your-app │
│ Content-Type: application/json │
│ Authorization: Bearer sk-ant-xxxxx │
│ │
│ ┌─────────────────────────────────┐ │
│ │ The actual letter (body/JSON) │ │
│ └─────────────────────────────────┘ │
└─────────────────────────────────────────┘
Common headers you'll use:
| Header | Purpose | Example |
|---|---|---|
Content-Type | What format is the body | application/json |
Authorization | Who you are (API key) | Bearer sk-ant-xxxxx |
x-api-key | Anthropic's API key header | sk-ant-api03-xxxxx |
anthropic-version | Which API version to use | 2023-06-01 |
Accept | What format you want back | application/json |
What is JSON?
JSON (JavaScript Object Notation) is the language APIs use to exchange data. It's human-readable and machine-parseable.
{
"name": "Claude",
"type": "AI assistant",
"capabilities": ["text", "code", "analysis"],
"is_awesome": true,
"version": 3.5
}Rules of JSON:
- Keys are always strings in double quotes
- Values can be: strings, numbers, booleans, arrays, objects, or null
- No trailing commas
- No comments
When you send data to Claude's API, you send JSON. When Claude responds, it responds with JSON.
Real Example with cURL
cURL is a command-line tool for making HTTP requests. Here's a real request to Claude's API:
curl https://api.anthropic.com/v1/messages \
-H "content-type: application/json" \
-H "x-api-key: $ANTHROPIC_API_KEY" \
-H "anthropic-version: 2023-06-01" \
-d '{
"model": "claude-sonnet-4-20250514",
"max_tokens": 1024,
"messages": [
{
"role": "user",
"content": "What is HTTP in one sentence?"
}
]
}'Breaking it down:
| Part | What it does |
|---|---|
curl | The HTTP client tool |
https://api.anthropic... | The URL (where to send) |
-H "content-type:..." | A header (we're sending JSON) |
-H "x-api-key:..." | A header (our API key) |
-H "anthropic-version.." | A header (API version) |
-d '{...}' | The body (our message to Claude) |
The response comes back as JSON:
{
"id": "msg_01XFDUDYJgAACzvnptvVoYEL",
"type": "message",
"role": "assistant",
"content": [
{
"type": "text",
"text": "HTTP is a protocol that defines how clients and servers communicate over the web by exchanging requests and responses."
}
],
"model": "claude-sonnet-4-20250514",
"stop_reason": "end_turn",
"usage": {
"input_tokens": 15,
"output_tokens": 28
}
}How This Relates to Claude's API
Everything we just learned maps directly to how you'll use Claude:
┌────────────────────────────────────────────────────┐
│ │
│ Your App Anthropic Server │
│ ──────── ──────────────── │
│ │
│ 1. Build a JSON body │
│ (model, messages, max_tokens) │
│ │
│ 2. POST it to │
│ https://api.anthropic.com/v1/messages │
│ │
│ 3. Include headers: │
│ - x-api-key (authentication) │
│ - content-type (format) │
│ - anthropic-version (API version) │
│ │
│ 4. Receive JSON response │
│ - status code (200 = success) │
│ - body (Claude's answer) │
│ - usage (tokens consumed) │
│ │
└────────────────────────────────────────────────────┘
Whether you use cURL, Python, Node.js, or any SDK — underneath, it's all just HTTP requests and responses.
The Complete Picture
You write code
│
v
SDK builds an HTTP Request
│
├── Method: POST
├── URL: https://api.anthropic.com/v1/messages
├── Headers: API key, Content-Type, Version
└── Body: JSON with model + messages
│
v
┌──────────────┐
│ Internet │
│ (HTTPS) │
└──────┬───────┘
│
v
Anthropic Server
processes your request
│
v
Server sends HTTP Response
│
├── Status: 200 OK
├── Headers: request-id, content-type
└── Body: JSON with Claude's answer
│
v
SDK parses the response
│
v
You get Claude's message!
Key Takeaways
- HTTP is the protocol that powers the web and all APIs
- A URL is an address with protocol, domain, path, and parameters
- Requests go from you to the server; responses come back
- Methods (GET, POST, PUT, DELETE) describe what you want to do
- Status codes tell you if it worked (2xx) or failed (4xx, 5xx)
- Headers carry metadata like your API key and content type
- JSON is the data format used to send and receive information
- Claude's API uses POST requests with JSON bodies over HTTPS