2.7. HTTP and HTTPS
Table of Contents
Why HTTP and HTTPS Matter for Backend Developers
When you build a backend, almost every client talks to your server using HTTP or HTTPS. Understanding them is critical, because:
- Every API request and response uses HTTP.
- Security on the web is mostly about using HTTPS correctly.
- Tools like browsers, curl, Postman, and proxies all speak HTTP.
This chapter focuses on what is specific to HTTP and HTTPS: how they look on the wire, how they differ, and what they mean for you as a backend developer.
What Is HTTP?
HTTP stands for HyperText Transfer Protocol. It is an application-level protocol that defines how clients and servers communicate text-based messages over the network.
A simple description:
- HTTP is a set of rules for:
- how a request is formatted,
- how a response is formatted,
- what each part means.
- HTTP itself does not care how data moves across the wire. Lower levels like TCP/IP handle that.
You will see HTTP in:
- Web pages (browser to web server).
- REST APIs (client apps to backend).
- Mobile apps (phone apps to your backend).
- CLI tools (curl, httpie) when they call APIs.
HTTP is stateless: the server does not remember previous requests automatically. Each request is independent. Sessions and cookies (covered later in the course) are built on top of HTTP to simulate “remembering” users.
Versions of HTTP
There are several versions of HTTP in common use:
| Version | Main idea | Typical use today |
|---|---|---|
| HTTP/1.0 | Simple, one request per connection | Mostly historical, rarely used explicitly |
| HTTP/1.1 | Persistent connections, more headers | Still extremely common in many backends |
| HTTP/2 | Multiplexing, header compression, binary | Widely used via browsers and CDNs |
| HTTP/3 | Uses QUIC over UDP, better performance on bad networks | Growing adoption, modern browsers |
As a beginner, you mostly need to understand the concepts of HTTP and the message format. HTTP/1.1 is the easiest to read and reason about as text. HTTP/2 and HTTP/3 are more efficient, but high-level concepts like methods, URLs, headers, and status codes remain the same.
HTTP Request and Response Structure (High Level)
The details of the request/response cycle will be explained in a dedicated chapter, but here is a short look at how HTTP uses plain text messages.
An HTTP request consists of:
- A request line
Example:
GET /products?limit=10 HTTP/1.1 - Headers (zero or more)
Example:
Host: example.com
User-Agent: Mozilla/5.0
Accept: application/json - A blank line
- An optional body (for example for POST or PUT)
Example:
{ "name": "New product" }
An HTTP response consists of:
- A status line
Example:
HTTP/1.1 200 OK - Headers
Example:
Content-Type: application/json
Content-Length: 27 - A blank line
- An optional body
Example:
{ "status": "success" }
You will work with all of these in detail in later chapters: HTTP Requests, HTTP Responses, HTTP Methods, HTTP Status Codes, and HTTP Headers.
What Is HTTPS?
HTTPS is HTTP over TLS. It is the same protocol (same methods, URLs, headers, status codes), but the data is encrypted and authenticated.
- HTTP: data is sent in plain text over TCP.
- HTTPS: HTTP data is wrapped inside TLS, which provides:
- Encryption,
- Integrity (data is not changed in transit),
- Authentication (server identity, via certificates).
The S in HTTPS stands for Secure.
From your point of view as a backend developer:
- Your application still works with regular HTTP constructs.
- The web server (for example Nginx, a cloud load balancer, or a reverse proxy) handles TLS encryption and decryption.
- Inside your code, you usually see “plain” HTTP requests, even when clients connect via HTTPS.
Important rule: Always use HTTPS in production.
Sending passwords, tokens, or any sensitive data over plain HTTP is insecure and must be avoided.
Plain HTTP vs HTTPS: What Changes?
URL Scheme
The URL scheme tells the client whether to use HTTP or HTTPS:
| Scheme | Example URL | Default port |
|---|---|---|
http | http://example.com/api/users | 80 |
https | https://example.com/api/users | 443 |
When you open a site with https:// the browser:
- Initiates a TCP connection to port 443.
- Performs a TLS handshake.
- Then sends HTTP data inside the encrypted TLS stream.
With http:// it uses port 80 and sends HTTP in plain text without TLS.
Ports
- HTTP default port: 80
- HTTPS default port: 443
You can change ports:
http://localhost:8000/https://api.example.com:8443/
In practice, production sites usually stick to the defaults.
Visibility of Data
With HTTP:
- Anyone who can see the network traffic (for example on public Wi-Fi, some ISPs, or compromised routers) can read:
- URLs and query strings,
- headers,
- cookies,
- body content including passwords or tokens.
With HTTPS:
- The data is encrypted in transit.
- Observers can see that you connect to a host (like
example.com), but not the exact path, the request body, or headers content (with some minor exceptions such as SNI revealing hostnames).
What TLS Adds on Top of HTTP
HTTPS uses TLS (Transport Layer Security). You do not need the full cryptography details now, but you should know what benefits it provides.
TLS provides three main properties:
1. Encryption
Data between client and server is unreadable to anyone else.
Example:
- With HTTP:
- Your login POST body might look like:
POST /login HTTP/1.1
Host: example.com
Content-Type: application/json
{ "email": "user@example.com", "password": "mypassword123" }A network sniffer can read this directly.
- With HTTPS:
- The same HTTP text is wrapped inside TLS, and a sniffer sees only encrypted bytes.
2. Integrity
TLS protects against modifications in transit.
- If an attacker tries to change the response body (for example altering JSON data), TLS will detect that the data has been tampered with.
- TCP ensures packets arrive and reorders them, but does not detect malicious changes. TLS adds cryptographic integrity checks.
3. Authentication (Server Identity)
TLS uses certificates to prove the identity of the server.
When you see a lock icon in the browser:
- The browser has verified that the server presented a certificate for a domain like
api.example.com. - The certificate is signed by a trusted Certificate Authority (CA).
- If the certificate is invalid or self-signed, the browser shows a warning.
As a backend developer, you must ensure:
- Your production site uses a valid certificate.
- It is configured correctly on the web server or load balancer.
The Basic HTTPS Connection Flow
At a high level, this is what happens when a client uses HTTPS:
- Client connects to
example.com:443using TCP. - Client and server perform a TLS handshake:
- Negotiate cryptographic algorithms.
- Exchange keys.
- Validate the server certificate.
- Once the TLS handshake succeeds, a secure channel is established.
- Client sends HTTP requests inside this secure channel.
- Server sends HTTP responses back through the same secure channel.
The important part: your API code sees regular HTTP requests after decryption. Most of the TLS complexity is handled by web servers and libraries.
Example: HTTP vs HTTPS in Practice
Example 1: Simple GET for a public API
HTTP (insecure):
GET /api/products HTTP/1.1
Host: api.example.com
Accept: application/jsonHTTPS (secure):
- On the wire, the raw text above is encrypted.
- Inside your backend framework, your handler receives a normal HTTP request: method, path, headers, etc.
Example 2: Login Request
HTTP:
POST /login HTTP/1.1
Host: example.com
Content-Type: application/json
{ "email": "user@example.com", "password": "SuperSecret!" }With plain HTTP:
- Anyone on the same network can read the password.
- Cookies or tokens in headers are exposed.
With HTTPS:
- Same HTTP structure, but travels in an encrypted tunnel.
- Attackers cannot read the email or password.
This is why login forms and APIs must use HTTPS.
Why Browsers Push HTTPS
Modern browsers strongly favor HTTPS:
- The lock icon or similar indication shows a secure connection.
- Many browser features are only available on HTTPS origins, for example:
- Service workers,
- Push notifications,
- Some advanced APIs.
- Browsers often mark HTTP pages as “Not Secure” especially if they contain form fields.
As a backend developer:
- Plan all production endpoints to be served via HTTPS.
- Redirect all HTTP traffic to HTTPS wherever possible, for example using an HTTP 301 “Moved Permanently” response.
Example redirect:
HTTP/1.1 301 Moved Permanently
Location: https://example.com/loginHTTP vs HTTPS: Summary Table
| Aspect | HTTP | HTTPS |
|---|---|---|
| Full name | HyperText Transfer Protocol | HTTP over TLS (Secure HTTP) |
| Encryption | No, plain text | Yes, contents are encrypted |
| Default port | 80 | 443 |
| Security | Vulnerable to snooping and tampering | Protects confidentiality and integrity |
| Certificates | Not used | Uses TLS certificates issued by CAs |
| Browser status | Often “Not secure” for forms or logins | Lock icon, considered secure if correctly set up |
Key statement:
Use HTTP for local development only, and HTTPS for any real users or sensitive data in production.
How This Affects Backend Development
You will usually see HTTPS in these contexts:
- Local development
- Often use HTTP, for example:
http://localhost:8000. - Less overhead, no need to manage certificates.
- Traffic stays on your machine, so encryption is less critical.
- Staging and production
- Must use HTTPS for real users and real data.
- Typically configured via:
- Cloud provider load balancers (AWS ALB, GCP, etc.),
- Reverse proxies (Nginx, Traefik),
- Services like Cloudflare.
- You might use services like Let’s Encrypt for free certificates.
- Internal microservices
- Sometimes use HTTP inside a private network, and HTTPS only at the public edge.
- Sometimes use HTTPS between internal services as well, depending on security requirements.
- APIs and mobile apps
- Mobile apps or SPA frontends call your backend using HTTPS.
- You must provide HTTPS endpoints so clients can trust your server and protect user data.
Recognizing HTTP / HTTPS in Tools
Browser Developer Tools
- In the Network tab, you will see
https://for secure requests. - Status column often shows a lock or details about the connection.
- You can inspect headers and bodies, the browser decrypts them for you.
curl
Using HTTP:
curl http://example.com/api/usersUsing HTTPS:
curl https://example.com/api/usersAdding details:
curl -v https://example.com/api/users
The -v flag shows TLS handshake steps and certificate information.
Postman / API clients
- You specify the full URL, for example
https://api.example.com/v1/users. - The client handles HTTPS automatically, including certificate validation.
- If the certificate is self-signed (common in development), clients might show warnings or require extra configuration.
Common Pitfalls for Beginners
Confusing HTTP with HTTPS
Remember:
- HTTP is the protocol.
- HTTPS is HTTP + TLS.
Your application logic (routes, controllers, handlers) usually works the same. The difference is at the network and server configuration level.
Sending Sensitive Data Over HTTP
Never send:
- Passwords,
- Session cookies,
- Access tokens,
- Personal user data
over plain HTTP in real environments. Use HTTPS.
Incorrect Redirects
Common pattern:
- Client visits
http://example.com. - Server responds with a redirect to
https://example.com.
Ensure:
- You redirect with status 301 or 302.
- You do not accidentally redirect in a loop (for example, redirecting HTTPS to HTTP then back).
Mixed Content
If your frontend is loaded over HTTPS, all its resources (APIs, images, scripts) should also be HTTPS.
If you try to call http:// API endpoints from an https:// page, browsers may block the request as “mixed content”.
Looking Ahead
In later chapters, you will dive into:
- HTTP Requests
Detailed structure of request lines, headers, and bodies. - HTTP Responses
How to construct correct responses. - HTTP Methods
GET, POST, PUT, DELETE, etc, and how they are used in APIs. - HTTP Status Codes
200, 201, 400, 404, 500, and others. - HTTP Headers
Content-Type, Authorization, Cookie, CORS-related headers, and more.
For all of these topics, the concepts are the same whether you use HTTP or HTTPS. HTTPS simply wraps all this communication in a secure envelope.
Quick Recap
- HTTP is the text-based protocol for communication between clients and servers.
- HTTPS is HTTP secured by TLS, which adds:
- Encryption,
- Integrity,
- Server authentication via certificates.
- Use HTTP locally for learning and small experiments, but always use HTTPS in production.
- Your backend code mostly deals with HTTP concepts, while HTTPS configuration is handled by web servers, infrastructure, or frameworks.
Understanding this foundation will make it easier to reason about APIs, security, and deployment as you move through the rest of the course.
Views: 10
KAHIBARO