HomeGetting StartedHow the Internet Works (HTTP Basics)
beginner10 min read· Module 2, Lesson 1

🌐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
PartExampleWhat it does
Protocolhttps://How to communicate (secure HTTP)
Domainapi.anthropic.comWhich server to talk to
Path/v1/messagesWhich resource on that server
Params?model=claude-3Extra 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

FeatureHTTPHTTPS
Full nameHyperText Transfer ProtocolHyperText Transfer Protocol Secure
EncryptedNoYes (uses TLS/SSL)
Safe for APIsNoYes
Port80443

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:

  1. Method — what action you want (GET, POST, etc.)
  2. URL — where to send it
  3. Headers — metadata about the request
  4. 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:

MethodActionExampleAnalogy
GETReadGet a list of modelsReading a menu
POSTCreateSend a message to ClaudePlacing an order
PUTUpdateReplace entire user profileRewriting a document
PATCHPartialUpdate just the user's nameEditing one line
DELETERemoveDelete a fine-tuned modelThrowing 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:

CodeMeaningEmojiWhen it happens
200OKRequest succeeded
201Created🆕New resource was created
400Bad RequestYour request has errors (bad JSON, etc.)
401Unauthorized🔒Invalid or missing API key
403Forbidden🚫Valid key but no permission
404Not Found🔍The endpoint doesn't exist
429Rate LimitedToo many requests — slow down
500Server 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:

HeaderPurposeExample
Content-TypeWhat format is the bodyapplication/json
AuthorizationWho you are (API key)Bearer sk-ant-xxxxx
x-api-keyAnthropic's API key headersk-ant-api03-xxxxx
anthropic-versionWhich API version to use2023-06-01
AcceptWhat format you want backapplication/json

What is JSON?

JSON (JavaScript Object Notation) is the language APIs use to exchange data. It's human-readable and machine-parseable.

JSON
{ "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:

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

PartWhat it does
curlThe 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:

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

  1. HTTP is the protocol that powers the web and all APIs
  2. A URL is an address with protocol, domain, path, and parameters
  3. Requests go from you to the server; responses come back
  4. Methods (GET, POST, PUT, DELETE) describe what you want to do
  5. Status codes tell you if it worked (2xx) or failed (4xx, 5xx)
  6. Headers carry metadata like your API key and content type
  7. JSON is the data format used to send and receive information
  8. Claude's API uses POST requests with JSON bodies over HTTPS