Learn what HTTP is, how it works, the difference between HTTP and HTTPS - everything about web communication from basics to advanced.
What is HTTP and how does web communication work
HTTP (HyperText Transfer Protocol) is the foundation of web communication. Learn what it is and why it matters.
HTTP (HyperText Transfer Protocol) is the protocol used for transmitting data over the web. It defines how messages are formatted and transmitted between web browsers and servers.
Think of HTTP like the postal system:
Just like postal rules ensure your letter reaches the destination, HTTP ensures your web requests reach the correct server!
www.google.com in browserGET /search?q=hello HTTP/1.1
Host: www.google.com
User-Agent: Mozilla/5.0
Accept: text/html
HTTP/1.1 200 OK
Content-Type: text/html
Content-Length: 45678
<!DOCTYPE html>
<html>
<head><title>Google</title></head>
<body>...</body>
</html>
| Property | Description |
|---|---|
| Stateless | Each request is independent, server doesn't remember previous requests |
| Text-based | Messages are human-readable text |
| Request-Response | Client sends request, server sends response |
| Application Layer | Works on top of TCP/IP |
https://httpbin.org/getThe crucial difference between HTTP and HTTPS - why the 'S' matters for your security.
HTTP = Data sent as plain text (anyone can read it)
HTTPS = Data is encrypted (only sender and receiver can read it)
| Feature | HTTP | HTTPS |
|---|---|---|
| Full Name | HyperText Transfer Protocol | HyperText Transfer Protocol Secure |
| Port | 80 | 443 |
| URL Prefix | http:// | https:// |
| Encryption | None | TLS/SSL |
| Security | Not secure | Secure |
| Certificate | Not required | SSL Certificate required |
| Speed | Slightly faster | Slightly slower (encryption overhead) |
| SEO | Lower ranking | Higher ranking (Google prefers HTTPS) |
HTTP Request (Plain Text - Anyone can see):
POST /login
username=john&password=secret123
HTTPS Request (Encrypted - Looks like):
POST /login
x7#kL9$mN2@pQ5... (gibberish to attackers)
https://http://httpbin.org/gethttps://httpbin.org/getThe complete journey of an HTTP request from your browser to the server and back.
CLIENT (Browser) SERVER (Website)
| |
| 1. DNS Lookup |
| (Find server IP address) |
| |
| 2. TCP Connection |
|----------------------------------->|
| (3-way handshake) |
| |
| 3. HTTP Request |
|----------------------------------->|
| GET /page.html HTTP/1.1 |
| |
| 4. Server Processing |
| [Process Request]
| |
| 5. HTTP Response |
|<-----------------------------------|
| HTTP/1.1 200 OK |
| + HTML content |
| |
| 6. Render Page |
| [Display in browser] |
Browser converts domain name to IP address:
www.example.com → 93.184.216.34
Browser establishes connection with server (3-way handshake):
Client: SYN (Hey, want to connect?)
Server: SYN-ACK (Sure, let's connect!)
Client: ACK (Great, we're connected!)
Browser sends the actual request:
GET /index.html HTTP/1.1
Host: www.example.com
User-Agent: Mozilla/5.0
Accept: text/html
Accept-Language: en-US
Connection: keep-alive
Server receives request, processes it, prepares response
Server sends back the response:
HTTP/1.1 200 OK
Content-Type: text/html
Content-Length: 1234
Date: Fri, 24 Jan 2025 10:00:00 GMT
<!DOCTYPE html>
<html>...</html>
Browser parses HTML, loads CSS/JS, displays page
| Type | Behavior |
|---|---|
| Non-persistent (HTTP/1.0) | New connection for each request |
| Persistent (HTTP/1.1) | Reuse connection for multiple requests |
| Multiplexed (HTTP/2) | Multiple requests on single connection simultaneously |
Detailed breakdown of what's inside an HTTP request and response message.
┌─────────────────────────────────────────┐
│ Request Line │
│ GET /api/users HTTP/1.1 │
├─────────────────────────────────────────┤
│ Headers │
│ Host: api.example.com │
│ User-Agent: HttpNinja/1.0 │
│ Accept: application/json │
│ Authorization: Bearer token123 │
├─────────────────────────────────────────┤
│ Empty Line │
├─────────────────────────────────────────┤
│ Body (optional) │
│ {"name": "John", "email": "j@test.com"} │
└─────────────────────────────────────────┘
| Component | Example | Description |
|---|---|---|
| Method | GET | What action to perform |
| Path | /api/users | Resource location |
| Version | HTTP/1.1 | Protocol version |
┌─────────────────────────────────────────┐
│ Status Line │
│ HTTP/1.1 200 OK │
├─────────────────────────────────────────┤
│ Headers │
│ Content-Type: application/json │
│ Content-Length: 256 │
│ Date: Fri, 24 Jan 2025 10:00:00 GMT │
│ Server: nginx/1.18.0 │
├─────────────────────────────────────────┤
│ Empty Line │
├─────────────────────────────────────────┤
│ Body │
│ {"id": 1, "name": "John"} │
└─────────────────────────────────────────┘
| Component | Example | Description |
|---|---|---|
| Version | HTTP/1.1 | Protocol version |
| Status Code | 200 | Numeric result code |
| Status Text | OK | Human-readable status |
// REQUEST
POST /api/login HTTP/1.1
Host: api.example.com
Content-Type: application/json
Content-Length: 45
{"username": "john", "password": "secret"}
// RESPONSE
HTTP/1.1 200 OK
Content-Type: application/json
Set-Cookie: session=abc123; HttpOnly
{"success": true, "token": "eyJhbGc..."}
https://httpbin.org/post{"test": "data"}Deep dive into HTTP methods, status codes, and headers
GET, POST, PUT, DELETE and more - understand what each HTTP method does and when to use it.
HTTP methods (also called verbs) indicate the desired action to perform on a resource. Different methods have different purposes and behaviors.
| Method | Purpose | Has Body | Idempotent | Safe |
|---|---|---|---|---|
| GET | Retrieve data | No | Yes | Yes |
| POST | Create new data | Yes | No | No |
| PUT | Replace entire resource | Yes | Yes | No |
| PATCH | Partial update | Yes | No | No |
| DELETE | Remove resource | No | Yes | No |
GET /api/users/123 HTTP/1.1
Host: api.example.com
// Response: User data
POST /api/users HTTP/1.1
Content-Type: application/json
{"name": "John", "email": "john@test.com"}
// Response: Created user with new ID
PUT /api/users/123 HTTP/1.1
Content-Type: application/json
{"name": "John Updated", "email": "new@test.com", "age": 30}
// Replaces ALL fields of user 123
PATCH /api/users/123 HTTP/1.1
Content-Type: application/json
{"email": "newemail@test.com"}
// Only updates email, keeps other fields
DELETE /api/users/123 HTTP/1.1
// Deletes user 123
| Method | Purpose |
|---|---|
| HEAD | Same as GET but returns only headers, no body |
| OPTIONS | Returns allowed methods for a resource |
| TRACE | Echoes the request (for debugging) |
| CONNECT | Establishes tunnel (used for HTTPS proxy) |
https://jsonplaceholder.typicode.com/posts/1https://jsonplaceholder.typicode.com/postshttps://jsonplaceholder.typicode.com/posts/1https://jsonplaceholder.typicode.com/posts/1200, 404, 500 - learn what every HTTP status code means and when they occur.
| Range | Category | Meaning | Color |
|---|---|---|---|
| 1xx | Informational | Request received, processing | Blue |
| 2xx | Success | Request successful | Green |
| 3xx | Redirection | Further action needed | Yellow |
| 4xx | Client Error | Bad request from client | Orange |
| 5xx | Server Error | Server failed | Red |
| Code | Name | Meaning | Common Use |
|---|---|---|---|
| 200 | OK | Request succeeded | GET, PUT success |
| 201 | Created | Resource created | POST success |
| 204 | No Content | Success, no body | DELETE success |
| 206 | Partial Content | Partial data returned | Video streaming |
| Code | Name | Meaning |
|---|---|---|
| 301 | Moved Permanently | Resource moved to new URL forever |
| 302 | Found | Temporary redirect |
| 304 | Not Modified | Use cached version |
| 307 | Temporary Redirect | Redirect keeping method |
| 308 | Permanent Redirect | Permanent redirect keeping method |
| Code | Name | Meaning | How to Fix |
|---|---|---|---|
| 400 | Bad Request | Invalid syntax | Check request format |
| 401 | Unauthorized | Authentication required | Login first |
| 403 | Forbidden | No permission | Check access rights |
| 404 | Not Found | Resource doesn't exist | Check URL |
| 405 | Method Not Allowed | Method not supported | Use correct method |
| 408 | Request Timeout | Request took too long | Try again |
| 409 | Conflict | Conflicting request | Resolve conflict |
| 422 | Unprocessable Entity | Validation error | Fix data |
| 429 | Too Many Requests | Rate limit exceeded | Wait and retry |
| Code | Name | Meaning |
|---|---|---|
| 500 | Internal Server Error | Server crashed/bug |
| 501 | Not Implemented | Feature not supported |
| 502 | Bad Gateway | Invalid response from upstream |
| 503 | Service Unavailable | Server overloaded/maintenance |
| 504 | Gateway Timeout | Upstream server timeout |
https://httpbin.org/status/200 - Successhttps://httpbin.org/status/301 - Redirecthttps://httpbin.org/status/404 - Not Foundhttps://httpbin.org/status/500 - Server ErrorContent-Type, Authorization, Cache-Control - understand the most important HTTP headers.
Headers are key-value pairs that provide additional information about the request or response. They're like metadata for HTTP messages.
| Header | Purpose | Example |
|---|---|---|
| Host | Target server | api.example.com |
| User-Agent | Client identification | Mozilla/5.0... |
| Accept | Acceptable response types | application/json |
| Accept-Language | Preferred language | en-US,en;q=0.9 |
| Accept-Encoding | Acceptable compression | gzip, deflate |
| Content-Type | Body format | application/json |
| Content-Length | Body size in bytes | 256 |
| Authorization | Auth credentials | Bearer eyJ... |
| Cookie | Stored cookies | session=abc123 |
| Cache-Control | Caching directives | no-cache |
| Header | Purpose | Example |
|---|---|---|
| Content-Type | Body format | text/html; charset=utf-8 |
| Content-Length | Body size | 1234 |
| Content-Encoding | Compression used | gzip |
| Set-Cookie | Set a cookie | id=abc; HttpOnly |
| Cache-Control | Caching rules | max-age=3600 |
| Location | Redirect URL | /new-page |
| Server | Server software | nginx/1.18.0 |
| Date | Response timestamp | Fri, 24 Jan 2025... |
// Common MIME types
text/html - HTML pages
text/plain - Plain text
text/css - CSS stylesheets
application/json - JSON data
application/xml - XML data
application/javascript - JavaScript
application/pdf - PDF files
image/png - PNG images
image/jpeg - JPEG images
multipart/form-data - File uploads
application/x-www-form-urlencoded - Form data
APIs often use custom headers (usually prefixed with X-):
X-API-Key: your-api-key
X-Request-ID: uuid-here
X-RateLimit-Remaining: 99
X-Custom-Header: value
https://httpbin.org/headersUnderstanding URLs - protocol, domain, path, query strings, and fragments.
https://user:pass@api.example.com:8080/v1/users?page=1&limit=10#section
|_____| |_______| |_____________| |__| |______| |_____________| |______|
| | | | | | |
Scheme Userinfo Host Port Path Query String Fragment
| Component | Example | Description |
|---|---|---|
| Scheme | https | Protocol (http, https, ftp) |
| Userinfo | user:pass | Authentication (rarely used) |
| Host | api.example.com | Domain name or IP |
| Port | 8080 | Port number (default: 80/443) |
| Path | /v1/users | Resource location |
| Query | ?page=1&limit=10 | Parameters |
| Fragment | #section | Page section (not sent to server) |
// Basic format
?key1=value1&key2=value2
// Examples
?search=hello // Single param
?page=1&limit=20 // Multiple params
?tags=js&tags=python // Array (same key multiple times)
?filter[name]=john // Nested params
Special characters must be encoded in URLs:
| Character | Encoded | Example |
|---|---|---|
| Space | %20 or + | hello%20world |
| & | %26 | rock%26roll |
| = | %3D | 1%2B1%3D2 |
| ? | %3F | what%3F |
| / | %2F | path%2Fto |
| # | %23 | %23hashtag |
// Absolute URL (complete)
https://api.example.com/users/123
// Relative URLs (depends on current page)
/users/123 // From root
users/123 // From current path
../users/123 // Parent directory
?page=2 // Same path, different query
https://httpbin.org/get?name=John DoeHTTP/2, HTTP/3, caching, cookies, and security
Evolution of HTTP protocol - from HTTP/1.0 to HTTP/3 with QUIC.
| Version | Year | Key Features |
|---|---|---|
| HTTP/0.9 | 1991 | Simple GET only, no headers |
| HTTP/1.0 | 1996 | Headers, status codes, POST |
| HTTP/1.1 | 1997 | Keep-alive, chunked transfer, Host header |
| HTTP/2 | 2015 | Multiplexing, header compression, server push |
| HTTP/3 | 2022 | QUIC protocol, improved performance |
HTTP/1.1 (Sequential):
Request 1 -----> Response 1
Request 2 -----> Response 2
Request 3 -----> Response 3
HTTP/2 (Multiplexed):
Request 1 --|
Request 2 --|---> All responses arrive together
Request 3 --|
| Feature | HTTP/1.1 | HTTP/2 | HTTP/3 |
|---|---|---|---|
| Transport | TCP | TCP | QUIC (UDP) |
| Multiplexing | No | Yes | Yes |
| Header Compression | No | HPACK | QPACK |
| Server Push | No | Yes | Yes |
| Encryption | Optional | Required* | Built-in |
How cookies work, session management, and cookie security attributes.
HTTP is stateless - server doesn't remember you between requests. Cookies solve this by storing data on the client that's sent with every request.
1. First Request (No cookie)
GET /login
2. Server Response (Sets cookie)
Set-Cookie: session=abc123; HttpOnly
3. Subsequent Requests (Cookie sent automatically)
GET /dashboard
Cookie: session=abc123
Set-Cookie: name=value; attribute1; attribute2
// Example with all attributes
Set-Cookie: session=abc123;
Expires=Thu, 01 Jan 2026 00:00:00 GMT;
Max-Age=31536000;
Domain=example.com;
Path=/;
Secure;
HttpOnly;
SameSite=Strict
| Attribute | Purpose | Example |
|---|---|---|
| Expires | Expiration date | Thu, 01 Jan 2026... |
| Max-Age | Lifetime in seconds | 3600 (1 hour) |
| Domain | Valid domain | .example.com |
| Path | Valid path | /admin |
| Secure | HTTPS only | (flag) |
| HttpOnly | No JavaScript access | (flag) |
| SameSite | Cross-site policy | Strict/Lax/None |
| Aspect | Cookie | Session |
|---|---|---|
| Storage | Client (browser) | Server |
| Size Limit | ~4KB | No limit |
| Security | Less secure | More secure |
| Expiry | Can persist | Usually temporary |
https://httpbin.org/cookies/set?name=valuehttps://httpbin.org/cookiesCache-Control, ETags, conditional requests - optimize performance with caching.
// Response headers
Cache-Control: max-age=3600 // Cache for 1 hour
Cache-Control: no-cache // Validate before using
Cache-Control: no-store // Never cache
Cache-Control: private // Only browser can cache
Cache-Control: public // Any cache can store
Cache-Control: must-revalidate // Must check if stale
First Request:
GET /image.png
→ 200 OK
Cache-Control: max-age=3600
ETag: "abc123"
Within 1 hour:
GET /image.png
→ Served from cache (no network)
After 1 hour (Conditional Request):
GET /image.png
If-None-Match: "abc123"
→ 304 Not Modified (use cache)
OR
→ 200 OK (new content)
| Response Header | Request Header | Purpose |
|---|---|---|
| ETag | If-None-Match | Content hash comparison |
| Last-Modified | If-Modified-Since | Date comparison |
https://httpbin.org/cache/60https://httpbin.org/etag/testUnderstanding CORS errors, preflight requests, and how to handle cross-origin requests.
CORS (Cross-Origin Resource Sharing) is a security feature that restricts web pages from making requests to a different domain than the one serving the page.
Origin = Protocol + Host + Port
https://example.com:443
Same origin:
https://example.com/page1 → https://example.com/api ✓
Different origin (blocked by default):
https://mysite.com → https://api.example.com ✗
http://example.com → https://example.com ✗ (different protocol)
https://example.com:8080 → https://example.com ✗ (different port)
| Header | Purpose | Example |
|---|---|---|
| Access-Control-Allow-Origin | Allowed origins | * or https://mysite.com |
| Access-Control-Allow-Methods | Allowed methods | GET, POST, PUT |
| Access-Control-Allow-Headers | Allowed headers | Content-Type, Authorization |
| Access-Control-Allow-Credentials | Allow cookies | true |
| Access-Control-Max-Age | Preflight cache time | 86400 |
For "non-simple" requests, browser sends OPTIONS request first:
// Preflight
OPTIONS /api/data
Origin: https://mysite.com
Access-Control-Request-Method: POST
Access-Control-Request-Headers: Content-Type
// Server Response
HTTP/1.1 204 No Content
Access-Control-Allow-Origin: https://mysite.com
Access-Control-Allow-Methods: POST
Access-Control-Allow-Headers: Content-Type
// Then actual request proceeds
POST /api/data
...
CORS is enforced by browsers only. HttpNinja is a native app, not a browser, so CORS restrictions don't apply. This makes it perfect for testing APIs that might fail in browser!
Getting "CORS error" in browser? Test the same API in HttpNinja - it will work without CORS restrictions!
Basic Auth, Bearer tokens, and the WWW-Authenticate challenge.
1. Client requests protected resource
GET /api/secret
2. Server responds with 401 and challenge
HTTP/1.1 401 Unauthorized
WWW-Authenticate: Basic realm="API"
3. Client sends credentials
GET /api/secret
Authorization: Basic dXNlcjpwYXNz
4. Server validates and responds
HTTP/1.1 200 OK
Username and password encoded in Base64:
// Format
Authorization: Basic base64(username:password)
// Example
username: admin
password: secret123
base64("admin:secret123") = "YWRtaW46c2VjcmV0MTIz"
Authorization: Basic YWRtaW46c2VjcmV0MTIz
Warning: Base64 is encoding, NOT encryption. Always use HTTPS with Basic Auth!
// Format
Authorization: Bearer
// Example with JWT
Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...
| Type | Header | Security | Use Case |
|---|---|---|---|
| Basic | Basic base64 | Low | Simple APIs |
| Bearer | Bearer token | Medium-High | Most APIs |
| Digest | Digest ... | Medium | Legacy systems |
| API Key | X-API-Key | Low-Medium | Public APIs |
https://httpbin.org/basic-auth/user/passThe best way to learn HTTP is by doing. Send real requests, inspect responses, and understand every header!
Download Free - Play Store