HyperText Transfer Protocol (HTTP) is an application-layer protocol for transmitting hypermedia documents, such as HTML. It forms the foundation of data communication on the World Wide Web and is designed for communication between web browsers and web servers.
HTTP follows a client-server model where:
HTTP is stateless by default, meaning each request is independent. State can be maintained through cookies, sessions, or tokens.
sequenceDiagram
participant Client
participant Server
Client->>Server: TCP Handshake
Client->>Server: HTTP Request (GET /index.html)
Server->>Client: HTTP Response (200 OK + HTML)
Client->>Server: HTTP Request (GET /style.css)
Server->>Client: HTTP Response (200 OK + CSS)
Note over Client,Server: Connection may close or stay open
| Method | Purpose | Safe | Idempotent | Cacheable |
|---|---|---|---|---|
| GET | Retrieve resource | Yes | Yes | Yes |
| POST | Create resource | No | No | Yes (if response) |
| PUT | Update/replace resource | No | Yes | No |
| DELETE | Remove resource | No | Yes | No |
| PATCH | Partial update | No | No | No |
| HEAD | Get headers only | Yes | Yes | Yes |
| OPTIONS | Describe communication options | Yes | Yes | No |
| CONNECT | Establish tunnel | No | No | No |
| TRACE | Echo request | Yes | Yes | No |
| Code Range | Category | Examples |
|---|---|---|
| 1xx | Informational | 100 Continue, 101 Switching Protocols |
| 2xx | Successful | 200 OK, 201 Created, 204 No Content |
| 3xx | Redirection | 301 Moved Permanently, 302 Found, 304 Not Modified |
| 4xx | Client Error | 400 Bad Request, 401 Unauthorized, 404 Not Found |
| 5xx | Server Error | 500 Internal Server Error, 502 Bad Gateway, 503 Service Unavailable |
Headers provide metadata about requests and responses:
HTTPS (HTTP Secure) is HTTP over TLS/SSL. It provides encrypted communication and authentication between client and server.
HTTPS addresses HTTP’s security limitations:
HTTPS adds TLS encryption layer:
sequenceDiagram
participant Client
participant Server
Client->>Server: Client Hello (TLS version, cipher suites)
Server->>Client: Server Hello (chosen cipher, certificate)
Client->>Server: Key Exchange
Server->>Client: Finished
Client->>Server: Finished
Note over Client,Server: Encrypted HTTP traffic